History log of /openbsd-current/usr.sbin/bgpd/parse.y
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.463 22-May-2024 claudio

Convert bgpid, remote_bgpid and clusterid to host byte order.

Before the RDE used host byte order for remote_bgpid but all the other
code used network byte order. The reason for that was that bgpid was
initially an IPv4 address but since RFC 6286 in 2011 this is much more
relaxed and so it makes more sense to just treat them as numbers and
so host byte order.

OK tb@


# 1.462 24-Apr-2024 claudio

Remove 'announce capabilities' as neighbor config stanza.

There is no need to have an easy knob to get outdated or crappy
implementations to limp along. Instead the various default on
capabilities just need to be disabled (e.g. announce as-4byte no).

OK tb@


# 1.461 11-Apr-2024 tb

Remove repeated type declaration that makes bison unhappy

Fixes: https://github.com/openbgpd-portable/openbgpd-portable/issues/77

ok claudio


# 1.460 09-Apr-2024 claudio

Limit the number of provider ASnumbers to MAX_ASPA_SPAS_COUNT (10'000)
in the parser as well.

OK tb@


# 1.459 09-Apr-2024 claudio

Allow operators to enforce the presence of certain capabilities on sessions.

For simple capabilities this just adds enforce to the yes/no option of the
announce statement. For multi-protocol capabilities and add-path there is
an extra keyword. On top of this for add-path the enforcement requires the
neighbor to send a matching capability, e.g
'announce add-path recv enforce' requires the other side to send any
'announce add-path send XYZ' capability.

This is mainly to enforce as-4byte and extra multi-protocol capabilities.

OK denis@ tb@


# 1.458 03-Apr-2024 claudio

Rewrite str2key() to not use strtoul() to convert 2 hexdigits into one
char. Instead use a simple function to do the conversion per nibble.
OK deraadt@ tb@


# 1.457 20-Mar-2024 claudio

Cleanup AID handling.

- Loops over all valid AID should start with AID_MIN and go up to AID_MAX - 1
e.g. for (i = AID_MIN; i < AID_MAX; i++)
If for some reason AID_UNSPEC must be handled make that explicit in the
for loop.

- aid2afi() now returns an error for AID_UNSPEC since there is no valid
AFI SAFI combo for AID_UNSPEC.

- Add additional checks for AID_MIN where currently only AID_MAX was checked.
This affects imsg for route refresh and graceful restart.

- Simplify add-path capability handling. Only the negotiated add_path capa
sets the flag for AID_UNSPEC to help code to quickly check if any add-path
is active.

OK tb@


# 1.456 18-Mar-2024 claudio

Typecast char argument to isxdigit() to unsigned char since isxdigit()
only works that way correctly.
OK deraadt@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.455 16-Aug-2023 claudio

Remove per-AFI ASPA handling in bgpd internals

With draft-ietf-sidrops-aspa-profile-16 and
draft-ietf-sidrops-aspa-verification-15 the AFI dependence of ASPA
records was dropped. So remove this complication form the code.

This only removes the AFI handling internally in bgpd but still allows
the old syntax in aspa-set tables. The optional address family is just
ignored and records are merged together.

For RTR sessions draft-ietf-sidrops-8210bis has not yet been updated so
right now we still handle RTR sessions as specified there. The IPv4 and
IPv6 ASPA entries are handled in two trees and merged together into one
AFI independent tree. This is the best we can do for now until IETF
updates draft-ietf-sidrops-8210bis.

OK tb@ job@


# 1.454 28-Apr-2023 claudio

Add explicit default labels in switch() statements with error handling.
Right now these are not reachable. Should also clear some gcc warnings.
OK tb@


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.462 24-Apr-2024 claudio

Remove 'announce capabilities' as neighbor config stanza.

There is no need to have an easy knob to get outdated or crappy
implementations to limp along. Instead the various default on
capabilities just need to be disabled (e.g. announce as-4byte no).

OK tb@


# 1.461 11-Apr-2024 tb

Remove repeated type declaration that makes bison unhappy

Fixes: https://github.com/openbgpd-portable/openbgpd-portable/issues/77

ok claudio


# 1.460 09-Apr-2024 claudio

Limit the number of provider ASnumbers to MAX_ASPA_SPAS_COUNT (10'000)
in the parser as well.

OK tb@


# 1.459 09-Apr-2024 claudio

Allow operators to enforce the presence of certain capabilities on sessions.

For simple capabilities this just adds enforce to the yes/no option of the
announce statement. For multi-protocol capabilities and add-path there is
an extra keyword. On top of this for add-path the enforcement requires the
neighbor to send a matching capability, e.g
'announce add-path recv enforce' requires the other side to send any
'announce add-path send XYZ' capability.

This is mainly to enforce as-4byte and extra multi-protocol capabilities.

OK denis@ tb@


# 1.458 03-Apr-2024 claudio

Rewrite str2key() to not use strtoul() to convert 2 hexdigits into one
char. Instead use a simple function to do the conversion per nibble.
OK deraadt@ tb@


# 1.457 20-Mar-2024 claudio

Cleanup AID handling.

- Loops over all valid AID should start with AID_MIN and go up to AID_MAX - 1
e.g. for (i = AID_MIN; i < AID_MAX; i++)
If for some reason AID_UNSPEC must be handled make that explicit in the
for loop.

- aid2afi() now returns an error for AID_UNSPEC since there is no valid
AFI SAFI combo for AID_UNSPEC.

- Add additional checks for AID_MIN where currently only AID_MAX was checked.
This affects imsg for route refresh and graceful restart.

- Simplify add-path capability handling. Only the negotiated add_path capa
sets the flag for AID_UNSPEC to help code to quickly check if any add-path
is active.

OK tb@


# 1.456 18-Mar-2024 claudio

Typecast char argument to isxdigit() to unsigned char since isxdigit()
only works that way correctly.
OK deraadt@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.455 16-Aug-2023 claudio

Remove per-AFI ASPA handling in bgpd internals

With draft-ietf-sidrops-aspa-profile-16 and
draft-ietf-sidrops-aspa-verification-15 the AFI dependence of ASPA
records was dropped. So remove this complication form the code.

This only removes the AFI handling internally in bgpd but still allows
the old syntax in aspa-set tables. The optional address family is just
ignored and records are merged together.

For RTR sessions draft-ietf-sidrops-8210bis has not yet been updated so
right now we still handle RTR sessions as specified there. The IPv4 and
IPv6 ASPA entries are handled in two trees and merged together into one
AFI independent tree. This is the best we can do for now until IETF
updates draft-ietf-sidrops-8210bis.

OK tb@ job@


# 1.454 28-Apr-2023 claudio

Add explicit default labels in switch() statements with error handling.
Right now these are not reachable. Should also clear some gcc warnings.
OK tb@


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.461 11-Apr-2024 tb

Remove repeated type declaration that makes bison unhappy

Fixes: https://github.com/openbgpd-portable/openbgpd-portable/issues/77

ok claudio


# 1.460 09-Apr-2024 claudio

Limit the number of provider ASnumbers to MAX_ASPA_SPAS_COUNT (10'000)
in the parser as well.

OK tb@


# 1.459 09-Apr-2024 claudio

Allow operators to enforce the presence of certain capabilities on sessions.

For simple capabilities this just adds enforce to the yes/no option of the
announce statement. For multi-protocol capabilities and add-path there is
an extra keyword. On top of this for add-path the enforcement requires the
neighbor to send a matching capability, e.g
'announce add-path recv enforce' requires the other side to send any
'announce add-path send XYZ' capability.

This is mainly to enforce as-4byte and extra multi-protocol capabilities.

OK denis@ tb@


# 1.458 03-Apr-2024 claudio

Rewrite str2key() to not use strtoul() to convert 2 hexdigits into one
char. Instead use a simple function to do the conversion per nibble.
OK deraadt@ tb@


# 1.457 20-Mar-2024 claudio

Cleanup AID handling.

- Loops over all valid AID should start with AID_MIN and go up to AID_MAX - 1
e.g. for (i = AID_MIN; i < AID_MAX; i++)
If for some reason AID_UNSPEC must be handled make that explicit in the
for loop.

- aid2afi() now returns an error for AID_UNSPEC since there is no valid
AFI SAFI combo for AID_UNSPEC.

- Add additional checks for AID_MIN where currently only AID_MAX was checked.
This affects imsg for route refresh and graceful restart.

- Simplify add-path capability handling. Only the negotiated add_path capa
sets the flag for AID_UNSPEC to help code to quickly check if any add-path
is active.

OK tb@


# 1.456 18-Mar-2024 claudio

Typecast char argument to isxdigit() to unsigned char since isxdigit()
only works that way correctly.
OK deraadt@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.455 16-Aug-2023 claudio

Remove per-AFI ASPA handling in bgpd internals

With draft-ietf-sidrops-aspa-profile-16 and
draft-ietf-sidrops-aspa-verification-15 the AFI dependence of ASPA
records was dropped. So remove this complication form the code.

This only removes the AFI handling internally in bgpd but still allows
the old syntax in aspa-set tables. The optional address family is just
ignored and records are merged together.

For RTR sessions draft-ietf-sidrops-8210bis has not yet been updated so
right now we still handle RTR sessions as specified there. The IPv4 and
IPv6 ASPA entries are handled in two trees and merged together into one
AFI independent tree. This is the best we can do for now until IETF
updates draft-ietf-sidrops-8210bis.

OK tb@ job@


# 1.454 28-Apr-2023 claudio

Add explicit default labels in switch() statements with error handling.
Right now these are not reachable. Should also clear some gcc warnings.
OK tb@


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.460 09-Apr-2024 claudio

Limit the number of provider ASnumbers to MAX_ASPA_SPAS_COUNT (10'000)
in the parser as well.

OK tb@


# 1.459 09-Apr-2024 claudio

Allow operators to enforce the presence of certain capabilities on sessions.

For simple capabilities this just adds enforce to the yes/no option of the
announce statement. For multi-protocol capabilities and add-path there is
an extra keyword. On top of this for add-path the enforcement requires the
neighbor to send a matching capability, e.g
'announce add-path recv enforce' requires the other side to send any
'announce add-path send XYZ' capability.

This is mainly to enforce as-4byte and extra multi-protocol capabilities.

OK denis@ tb@


# 1.458 03-Apr-2024 claudio

Rewrite str2key() to not use strtoul() to convert 2 hexdigits into one
char. Instead use a simple function to do the conversion per nibble.
OK deraadt@ tb@


# 1.457 20-Mar-2024 claudio

Cleanup AID handling.

- Loops over all valid AID should start with AID_MIN and go up to AID_MAX - 1
e.g. for (i = AID_MIN; i < AID_MAX; i++)
If for some reason AID_UNSPEC must be handled make that explicit in the
for loop.

- aid2afi() now returns an error for AID_UNSPEC since there is no valid
AFI SAFI combo for AID_UNSPEC.

- Add additional checks for AID_MIN where currently only AID_MAX was checked.
This affects imsg for route refresh and graceful restart.

- Simplify add-path capability handling. Only the negotiated add_path capa
sets the flag for AID_UNSPEC to help code to quickly check if any add-path
is active.

OK tb@


# 1.456 18-Mar-2024 claudio

Typecast char argument to isxdigit() to unsigned char since isxdigit()
only works that way correctly.
OK deraadt@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.455 16-Aug-2023 claudio

Remove per-AFI ASPA handling in bgpd internals

With draft-ietf-sidrops-aspa-profile-16 and
draft-ietf-sidrops-aspa-verification-15 the AFI dependence of ASPA
records was dropped. So remove this complication form the code.

This only removes the AFI handling internally in bgpd but still allows
the old syntax in aspa-set tables. The optional address family is just
ignored and records are merged together.

For RTR sessions draft-ietf-sidrops-8210bis has not yet been updated so
right now we still handle RTR sessions as specified there. The IPv4 and
IPv6 ASPA entries are handled in two trees and merged together into one
AFI independent tree. This is the best we can do for now until IETF
updates draft-ietf-sidrops-8210bis.

OK tb@ job@


# 1.454 28-Apr-2023 claudio

Add explicit default labels in switch() statements with error handling.
Right now these are not reachable. Should also clear some gcc warnings.
OK tb@


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.458 03-Apr-2024 claudio

Rewrite str2key() to not use strtoul() to convert 2 hexdigits into one
char. Instead use a simple function to do the conversion per nibble.
OK deraadt@ tb@


# 1.457 20-Mar-2024 claudio

Cleanup AID handling.

- Loops over all valid AID should start with AID_MIN and go up to AID_MAX - 1
e.g. for (i = AID_MIN; i < AID_MAX; i++)
If for some reason AID_UNSPEC must be handled make that explicit in the
for loop.

- aid2afi() now returns an error for AID_UNSPEC since there is no valid
AFI SAFI combo for AID_UNSPEC.

- Add additional checks for AID_MIN where currently only AID_MAX was checked.
This affects imsg for route refresh and graceful restart.

- Simplify add-path capability handling. Only the negotiated add_path capa
sets the flag for AID_UNSPEC to help code to quickly check if any add-path
is active.

OK tb@


# 1.456 18-Mar-2024 claudio

Typecast char argument to isxdigit() to unsigned char since isxdigit()
only works that way correctly.
OK deraadt@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.455 16-Aug-2023 claudio

Remove per-AFI ASPA handling in bgpd internals

With draft-ietf-sidrops-aspa-profile-16 and
draft-ietf-sidrops-aspa-verification-15 the AFI dependence of ASPA
records was dropped. So remove this complication form the code.

This only removes the AFI handling internally in bgpd but still allows
the old syntax in aspa-set tables. The optional address family is just
ignored and records are merged together.

For RTR sessions draft-ietf-sidrops-8210bis has not yet been updated so
right now we still handle RTR sessions as specified there. The IPv4 and
IPv6 ASPA entries are handled in two trees and merged together into one
AFI independent tree. This is the best we can do for now until IETF
updates draft-ietf-sidrops-8210bis.

OK tb@ job@


# 1.454 28-Apr-2023 claudio

Add explicit default labels in switch() statements with error handling.
Right now these are not reachable. Should also clear some gcc warnings.
OK tb@


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.457 20-Mar-2024 claudio

Cleanup AID handling.

- Loops over all valid AID should start with AID_MIN and go up to AID_MAX - 1
e.g. for (i = AID_MIN; i < AID_MAX; i++)
If for some reason AID_UNSPEC must be handled make that explicit in the
for loop.

- aid2afi() now returns an error for AID_UNSPEC since there is no valid
AFI SAFI combo for AID_UNSPEC.

- Add additional checks for AID_MIN where currently only AID_MAX was checked.
This affects imsg for route refresh and graceful restart.

- Simplify add-path capability handling. Only the negotiated add_path capa
sets the flag for AID_UNSPEC to help code to quickly check if any add-path
is active.

OK tb@


# 1.456 18-Mar-2024 claudio

Typecast char argument to isxdigit() to unsigned char since isxdigit()
only works that way correctly.
OK deraadt@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.455 16-Aug-2023 claudio

Remove per-AFI ASPA handling in bgpd internals

With draft-ietf-sidrops-aspa-profile-16 and
draft-ietf-sidrops-aspa-verification-15 the AFI dependence of ASPA
records was dropped. So remove this complication form the code.

This only removes the AFI handling internally in bgpd but still allows
the old syntax in aspa-set tables. The optional address family is just
ignored and records are merged together.

For RTR sessions draft-ietf-sidrops-8210bis has not yet been updated so
right now we still handle RTR sessions as specified there. The IPv4 and
IPv6 ASPA entries are handled in two trees and merged together into one
AFI independent tree. This is the best we can do for now until IETF
updates draft-ietf-sidrops-8210bis.

OK tb@ job@


# 1.454 28-Apr-2023 claudio

Add explicit default labels in switch() statements with error handling.
Right now these are not reachable. Should also clear some gcc warnings.
OK tb@


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.456 18-Mar-2024 claudio

Typecast char argument to isxdigit() to unsigned char since isxdigit()
only works that way correctly.
OK deraadt@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.455 16-Aug-2023 claudio

Remove per-AFI ASPA handling in bgpd internals

With draft-ietf-sidrops-aspa-profile-16 and
draft-ietf-sidrops-aspa-verification-15 the AFI dependence of ASPA
records was dropped. So remove this complication form the code.

This only removes the AFI handling internally in bgpd but still allows
the old syntax in aspa-set tables. The optional address family is just
ignored and records are merged together.

For RTR sessions draft-ietf-sidrops-8210bis has not yet been updated so
right now we still handle RTR sessions as specified there. The IPv4 and
IPv6 ASPA entries are handled in two trees and merged together into one
AFI independent tree. This is the best we can do for now until IETF
updates draft-ietf-sidrops-8210bis.

OK tb@ job@


# 1.454 28-Apr-2023 claudio

Add explicit default labels in switch() statements with error handling.
Right now these are not reachable. Should also clear some gcc warnings.
OK tb@


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.455 16-Aug-2023 claudio

Remove per-AFI ASPA handling in bgpd internals

With draft-ietf-sidrops-aspa-profile-16 and
draft-ietf-sidrops-aspa-verification-15 the AFI dependence of ASPA
records was dropped. So remove this complication form the code.

This only removes the AFI handling internally in bgpd but still allows
the old syntax in aspa-set tables. The optional address family is just
ignored and records are merged together.

For RTR sessions draft-ietf-sidrops-8210bis has not yet been updated so
right now we still handle RTR sessions as specified there. The IPv4 and
IPv6 ASPA entries are handled in two trees and merged together into one
AFI independent tree. This is the best we can do for now until IETF
updates draft-ietf-sidrops-8210bis.

OK tb@ job@


# 1.454 28-Apr-2023 claudio

Add explicit default labels in switch() statements with error handling.
Right now these are not reachable. Should also clear some gcc warnings.
OK tb@


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.454 28-Apr-2023 claudio

Add explicit default labels in switch() statements with error handling.
Right now these are not reachable. Should also clear some gcc warnings.
OK tb@


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.453 26-Apr-2023 claudio

Add prototypes for geticmptypebyname() and geticmpcodebyname().
Needed for bison.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.452 21-Apr-2023 claudio

Adjust ext community handling to support the generic transitive communities
introduced with flowspec.
OK tb@


# 1.451 21-Apr-2023 claudio

Missing space noticed by Pablo Mendez Hernandez


# 1.450 21-Apr-2023 claudio

Sync common code with bgpctl with the version from there.
OK tb@


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.449 19-Apr-2023 claudio

Reshuffle the flowrule yacc rules to be in a more logical and alphabetical
order.


# 1.448 18-Apr-2023 tb

Rewrite some ugly for loops

This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio


# 1.447 18-Apr-2023 claudio

Implement the parser bits to process flowspec rules. Heavily inspired by
pfctl, in bgpd flowspec rules are written like pf rules (with a few
exceptions / extensions). As a result not all flowspec features are
available but that is OK.
OK tb@


# 1.446 05-Apr-2023 claudio

Refactor port definitions to also support service names like bgp.
OK tb@


# 1.445 05-Apr-2023 claudio

Rename family with af to follow pfctl/parse.y a bit more.
OK tb@


# 1.444 04-Apr-2023 claudio

Cleanup parse.y a bit. Move global defines a bit down. Move mrtdump and
network rules up into the grammar and switch the order of restricted
to be more like the rest.
OK tb@


# 1.443 03-Apr-2023 claudio

Add first step of flowspec support. This adds the bits to establish a
connection with SAFI 133. Right now any sent UPDATE with SAFI 133 is
simply ignored. At the moment SAFI 134 (flowspec for L3VPN) is unsupported.
OK tb@


Revision tags: OPENBSD_7_3_BASE
# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.442 09-Mar-2023 claudio

Major rework of RFC9234 support. My initial interpretation of the RFC was
too conservative. Fixes and changes include:

- add role output to bgpctl, also adjust the capability output.
Note, this changes the JSON output of neighbors a bit.
- adjust the config parser to enable the RFC9234 role capability when
there is a role set. iBGP and sessions with no role will not announce
the role capability.
- adjust the role capability announcement to be only on sessions that
use either AFI IPv4 or IPv6 and SAFI 1 (AID_INET, AID_INET6).
- if there is an OPEN notification indicating that the role capability
is bad only disable the capability if it is not enforced.
- Adjust capability negotiation, store remote_role on the peer since
the neighbors role is no longer needed by the RDE.
- inject the OTC attribute on ingress only for AID_INET and AID_INET6.
For other AIDs clear the F_ATTR_OTC_LOOP flag.
- Adjust the role logic in the RDE and use the peer->role (local role of
the system) for all checks. Also remove the check if the role capability
was negotiated between peers.
- In prefix_eligible() check also if the F_ATTR_OTC_LOOP flag is set.
The RFC requires that prefixes must be considered ineligible (and not
treat as withdraw as done before)
- When generating an UPDATE include the OTC attribute unless the AID is
neither AID_INET or AID_INET6.

Fixes https://github.com/openbgpd-portable/openbgpd-portable/issues/51
Reported by Pier Carlo Chiodi
OK tb@


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.441 30-Jan-2023 claudio

Alter the way extended communities are matched when part of the value
is auto-expanded or masked off.
Try to match against both 2- and 4-byte AS encoding and on insertion
check if expansion is actually possible and deny communities where both
community values are > USHRT_MAX.
OK tb@


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.440 24-Jan-2023 claudio

Implement filter and control message matching for ASAP.

This adds avs (ASPA validation state) which can be 'unknown', 'valid'
or 'invalid'. It behaves similar to ovs but the ASPA validation state
of paths from iBGP sessions is 'unknown' and the role of the ebgp session
is important to get the right validation state.

OK tb@


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.439 20-Jan-2023 claudio

Document the aspa-set table. While there remove the superfluous 'allow'
keyword.
OK tb@


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.438 04-Jan-2023 claudio

Add a per eBGP session role to the config.

This somewhat replaces the RFC 9234 open policy role. This is done because
ASPA requires the same role to be present to properly validate paths.
For iBGP sessions the role is forced to ROLE_NONE. If no role is set on
an ebgp session then 'announce policy' is forced to 'no'.
Also make sure the the role capability is only added if the role is set.
OK tb@


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.437 18-Nov-2022 claudio

Add plumbing for ASPA support. This implements the parser and part of the
logic in the rtr process. It does not implement the new RTR messages yet
but it is possible to specify an aspa-set in the config. Also the validation
code in the RDE is missing so this does not do anything.
With this in it will be possible to extend rpki-client to publish an
aspa-set as part of the openbgpd config file.
OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.436 21-Sep-2022 claudio

The values for fib_priority are OS dependent. To help portability move
the RTP_BGP and similar defines all into kroute.c and export them via
kr_default_prio() and kr_check_prio().
OK tb@


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.435 17-Aug-2022 claudio

Convert bzero() to memset(), bcmp() to memcmp() and bcopy() to memcpy().

The memory regions passed to memcpy() can not overlap so no need for memmove().
OK tb@ deraadt@


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.434 28-Jul-2022 deraadt

whitespace found during a read-thru; ok claudio


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.433 21-Jul-2022 claudio

Relax the config of add-path send and rde evaluate all

add-path send is kind of like rde evaluate all (at least if plus is used)
and so it kind of implies 'rde evaluate all' in that case. Removing the
check in neighbor_consistent() allows to setup sessions so that 'either or'
are used. This makes sense since peers may opt out of add-path by disabling
the capability on their side.
Based on report from Pier Carlo Chiodi
OK tb@
cvs: ----------------------------------------------------------------------


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.432 11-Jul-2022 claudio

Implement send side of RFC7911 ADD-PATH

This allows to send out more then one path per perfix to a neighbor that
supports add-path receive. OpenBGPD supports a few different modes to
select which paths to send:
- all: send all valid paths (the ones with a * in bgpctl output)
- best: send out only the single best path
- ecmp: send out paths that evaluate the same up and including
the nexthop metric
- as-wide-best: send out paths that evaluete the same up but not including
the nexthop metric
Currently ecmp and as-wide-best are the same. On top of this best, ecmp
and as-wide-best allow to include extra paths (e.g. best plus 2) and
for the multipath modes there is also a maximum (e.g. ecmp plus 2 max 4)

OK tb@


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.431 27-Jun-2022 claudio

Add support for RFC 9234 - Route Leak Prevention and Detection Using Roles

With this it is possible to send a role in the OPEN message and if that
was successful the RDE will add the new OTC attribute if necessary.
OK tb@


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.430 15-Jun-2022 claudio

Do not use defines from pfkeyv2.h in portable code.

Instead define our own algorithm enums for the IPsec code.
OK tb@ sthen@


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.429 09-Jun-2022 claudio

Properly error out if a variable does not exist. Need to pass back
ERROR to yylex() to make the parser fail nicely.
OK tb@


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.428 02-Jun-2022 claudio

Adjust lowest allowed routing priority to be bigger than RTP_LOCAL.
RTP_LOCAL is internally used by the kernel and is not available for
userland. The minimal usable routing prio is 2.
OK tb@


# 1.427 02-Jun-2022 claudio

Use a common idiom to check if the user supplied routing priority is
in range. Also rephrase the error message.
OK tb@


# 1.426 02-Jun-2022 claudio

Cleanup ktable_exists() usage and its warning message.

Check the return value in all cases and use a common idiom for this check.
OK tb@


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.425 31-May-2022 claudio

Implement a max communities filter match

When max-communities X is set on a filterrule the filter will match when
more than X communities are present in the path. In other words
max-communities 0 means no communities are allowed and max-communities 3
limits it up to 3 communities.
There is max-communities, max-ext-communities and max-large-communities
for each of the 3 community attributes. These three max checks can be used
together.
OK tb@ job@


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.424 23-May-2022 deraadt

whitespaces found when I went checking for something else


Revision tags: OPENBSD_7_1_BASE
# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.423 15-Mar-2022 claudio

Change how $macros are expanded in the config.

Expand $macros not only at the start of a yacc token but also inside STRING
elements. STRING elements are used e.g. for community specifications and
it makes sense to allow $FOO:$BAR to correctly expand. There is no expansion
of macros in quoted strings (both single and double quotes).

Factor out the macro expand logic and with this introduce its own lookup
buffer for the macro name. For expansion to work inside STRING the char
after the makro name must be a character not allowed in macro names (not
alpha-numerical or '_').

Add extra checks to set variables. Mainly restrict length of the name and
also make sure it does not include not allowed characters.
OK tb@


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.422 23-Feb-2022 claudio

Make it possible to bind and connect to non-default ports. This is mainly
for testing. Using alternate ports does not work for session using ipsec.
OK tb@ deraadt@


# 1.421 22-Feb-2022 claudio

Convert parse.y to use stdint.h types uintX_t instead of u_intX_t
OK tb@


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.420 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.419 01-Sep-2021 claudio

Implement roa-set data expiry. Every prefix in a roa-set can specify an
optional expires timestamp. The rtr process is walking the roa-set every
5min and removes every prefix that is expired.
With this stale RPKI data will slowly disapear and not linger around.
OK job@


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.418 09-Aug-2021 claudio

Implement reception of multiple paths per BGP session. This is one
side of RFC7911 and the send portion will follow.

The path-id is extracted from the NLRI encoding an put into struct
prefix. To do this the prefix_by_peer() function gets a path-id
argument. If a session is not path-id enabled this argument will
be always 0. If a session is path-id enabled the value is taken
from the NLRI and can be anything, including 0. The value has no
meaning in itself. Still to make sure the decision process is able
to break a tie the path-id is checked as the last step (this is not
part of the RFC but required).

OK benno@


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.417 17-Jun-2021 claudio

Implement RFC 7313 enhanced route refresh. It is off by default and
can be enabled with 'announce enhanced refresh yes'
Similar to graceful restart this allows to mark routes as stale, refresh
them and the flush out routes that are still stale. Enhanced route refresh
uses a begin of rr and a end of rr message to signal the various stages.
A future enhancement would be the addition of a timeout in case the EoRR
message is not sent in reasonable time.
OK denis@ job@


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.416 20-May-2021 claudio

Properly initalize the MRT config so that mrt_reconfigure() is doing the
right thing. This also fixes the bgpd -nv output for 'dump X {in,out}'
statements for peers.
Debugged with and tested by Paul de Weerd


Revision tags: OPENBSD_6_9_BASE
# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.415 15-Apr-2021 bluhm

On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with
an expected output. On big endian machines the order of the set
of communities is different. The parser used memcmp(3) to sort a
struct of integers. This depends of the endianess. The correct
way is to compare the integer fields in native byte order. With
this change, the resulting order is the same on i386 and powerpc64.
OK claudio@


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.414 02-Mar-2021 claudio

Introduce 'rde evaluate all' a mode to work around path hiding in IXP
route-server environments.

By default only the best path is sent to peers and if that path is filtered
then the path is hidden for that peer. On route-servers this is sometimes
not desried. For this 'rde evaluate all' will cause the evaluation process
to fall back to alternate routes and will redistribute the first non-filtered
path to the peer. This is very similar to per-peer RIBs but accomplishes
the same effect without the massive increase in memory usage. Compared to
the default mode this requires more CPU resources but it is probably less
than what per-peer RIBs would require.

'rde evaluate all' can be set and reset globally, on groups and on idividual
neighbors. It is not limited to route-server configs but route loops are
possible if not properly used.

OK benno@


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.413 16-Feb-2021 claudio

Add RTR support to OpenBGPD. Add basic support for the protocol.
The RTR client runs in a new process where the protocol handling is done
and when new data is available all sources are merged into one ROA set
which is then loaded into the RDE. The roa-set from the config is also
handled by the new RTR engine.
Tested by and ok job@


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.412 25-Jan-2021 claudio

RFC6472 discourages the use of AS_SET segements in ASPATH attributes.
The main reason is that AS_SET does not play nice with RPKI ROA.

Introduce a per neighbor and global config option
'reject as-set yes' and 'reject as-set no'
If set to yes received UPDATES with AS_SET segements are rejected.
This is done the same way other ASPATH soft-errors are handled. The UPDATE
is marked invalid and all prefixes are treated as withdraws.
`bgpctl show rib in error` can be used to show prefixes that where denied
and treated as withdraws because of errors.

By default this feature is off.

OK benno@


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.411 29-Dec-2020 claudio

In preparation for RTR support change the representation of the roa-set
in the parent to a simple RB tree based on struct roa. With this overlapping
ROAs (same prefix & source-as but different maxlen) are now merged in the RDE
when the lookup trie is constructed.
OK benno@


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.410 27-Oct-2020 claudio

Do not allow configuration of the same neighbor multiple times. For this
the parser needs to check if the remote address is already in the RB tree.
Additionally fixup get_id to also compare the remote_masklen and fix
some memory leaks on parser failures.
Fixes a bgpd fatal on reload reported by Pascal Mathis.
OK benno@


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

branches: 1.408.4;
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

branches: 1.406.4;
Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.409 26-Oct-2020 claudio

Fix a memory leak when parsing roa-set lists. If the prefixset_item is
already in the RB tree free the item we tried to add since the item form
the RB tree is used.
Memory leak found and fix provided by Felix Maurer ( felix at felix-maurer.de)


Revision tags: OPENBSD_6_8_BASE
# 1.408 10-May-2020 deraadt

In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.408 10-May-2020 deraadt

In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.407 08-May-2020 claudio

Do not use string litterals in the grammar ("{") it is not POSIX compliant
and also not needed. This just needs a char lookup ('{') like it is done
in all the other rules with '{'. With this parse.y can be compiled with
bison.
OK otto@ benno@


Revision tags: OPENBSD_6_7_BASE
# 1.406 23-Apr-2020 claudio

Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.406 23-Apr-2020 claudio

Store local-address by address family. This allows to configure both
an IPv4 and IPv6 local-address on a group and the neighbors bind to the
right local-address. Also implement 'no local-address' to reset a previously
set local address back to zero. This should help with IBGP and multihop
session config and hopefully reduce repetition in bgpd configs.
OK sthen@ benno@


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.405 16-Mar-2020 claudio

The assumption that in roa tables a prefix / source-as combo only appears
once in the input file is not correct. I thought the RPKI validators would
aggreagte these entries but that is not necessarily the case.
There are cases where prefixes show up with the same source-as multiple times
with different maxlen lenght. In those cases merge these multiple entries
and keep the one entry with the longest maxlen length since that is the VRP
which covers all others.
Found by job@ OK benno@


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.404 14-Feb-2020 claudio

Rename copy_filterset() to filterset_copy() and move it to rde_filter.c
where functions like filterset_move() live. Also initialize the dest
TAILQ in filterset_copy() as it is done in filterset_move().
OK benno@ phessler@


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.403 24-Jan-2020 claudio

Implement 'max-prefix NUM out' to limit the number of announced prefixes.
This is an easy safety switch to not leak full tables to upstreams and
peers. If the limit is hit a Cease notification is sent and the session
is closed.
This implements most of https://tools.ietf.org/html/draft-sa-idr-maxprefix-00
OK job@


Revision tags: OPENBSD_6_6_BASE
# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.402 27-Sep-2019 claudio

Move the code to initialize the cluster-id from merge_config() to
parse_config(). The first is not called on startup which results in bgpd
using 0.0.0.0 as cluster-id.
Found and fix provided by Rivo Nurges (Rivo dot Nurges at smit dot ee)
Thanks and OK claudio@


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.401 13-Aug-2019 claudio

When allocating a new peer set the reconf_action to RECONF_REINIT.
Also in merge_config() it is no longer needed to reset the reconf_action
of the new peers to RECONF_REINIT. merge_config() is not called on
startup and so some of the initialisation of new peers did not happen
correctly.

This fixes the md5 integration test since the md5 initialisation did not
happen early enough.


# 1.400 08-Aug-2019 claudio

Set the reconf state of listening addrs to RECONF_REINIT. This is what
the session engine expects and will allow to send out the config without
calling merge_config first.
OK sthen@


# 1.399 07-Aug-2019 claudio

Improve RIB reload behaviour. Especially when the rtable changes or the
route evaluation is modified. In both cases the softreconfig code will
now walk the RIB and ensure that everything is in proper sync.
Additionally remove 'route-collector yes|no' from the bgpd config, instead
use 'rde rib Loc-RIB no evaluate' with the benefit that you can alter
the setting now during runtime.
Tested and OK benno@


# 1.398 07-Aug-2019 claudio

Only templates can have a remote-as of 0 (as in uninitalised, trust the AS
from the OPEN message) any other use of AS 0 is forbidden. This makes
templates work again without any extra unwanted config.
OK benno@


# 1.397 05-Aug-2019 claudio

Cleanup config reload in the RDE. Use the bgpd_conf struct to store sets
and l3vpns instead of temporary globals. Also rework rde_reload_done to
free filters and sets earlier. The soft-reconfiguration process no longer
needs the previous filters / sets to do its work since there is a full
Adj-RIB-Out.
OK benno@


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.396 24-Jul-2019 benno

mrt.h only needs to be included by mrt.c
ok claudio@


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.395 24-Jul-2019 claudio

Refactor the way RIBs are parsed a bit. No functional change but should
make it easier to extend the rib definitions later on.
OK benno@


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.394 23-Jul-2019 claudio

Clean up RIB related kroute code. Introduce a way to flush a FIB table
from the RDE. Make sure that all nexthops don't get removed in the FIB
when a FIB table is removed. This should only happen for the main FIB.
Remove F_RIB_HASNOFIB which is just confusing since there is already
F_RIB_NOFIB and F_RIB_NOFIBSYNC.
OK benno@


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.393 17-Jul-2019 claudio

Change the Adj-RIB-Out to a per peer set of RB trees. The way RIB data
structures are linked does not scale for the Adj-RIB-Out and so inserts
and updates into the Adj-RIB-Out did not scale because of some linear
list traversals in hot paths.

A synthetic test with 4000 peers announcing one prefix each showed that
the initial convergence time dropped from around 1 hout to around 6min.

Note: because the Adj-RIB-Out is now per peer the order in which prefixes
are dumped in 'bgpctl show rib out' changed.

Tested and OK job@, benno@, phessler@


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.392 22-Jun-2019 claudio

Adjust peer id allocation a bit. Use defines for the various special
values and intervals. Mostly the same with the exception that peerself
is now id 1 and the first peer has id 2 -- was 0 and 1 before.
OK kn@, benno@


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.391 17-Jun-2019 claudio

Cleanup, remove some unneded spaces add some other where needed.
No binary change according to clang


# 1.390 17-Jun-2019 claudio

Completley rewrite the community matching and handling code. All community
attributes are put into a new data structure when parsing the UPDATE.
The filter code can quickly lookup and modify this data structure.
When creating an UPDATE the data is put back into wire format.
Setups using a lot of communities benefit a lot from this.
Input and OK benno@


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

branches: 1.386.2;
Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.389 31-May-2019 claudio

Also check the type of a network statement when looking for duplicates.
Fixes adding network 0.0.0.0/0 after network inet static.
OK phessler@ benno@


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.388 27-May-2019 claudio

Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers
are configured. In my test case the difference is around 20% runtime.
OK denis@


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.387 03-May-2019 claudio

Make sure that the as-set name is not too long when parsing the config file.
Fixes an assertion caught in new_as_set() parsing some arouteserver config.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


Revision tags: OPENBSD_6_5_BASE
# 1.386 10-Apr-2019 claudio

Include endian.h since htobe* or be*toh is used. Helps with protable.
OK deraadt@


# 1.385 31-Mar-2019 claudio

Move the struct peer into bgpd_config and switch it to a TAILQ instead of
the hand-rolled list. This changes the way peers are reloaded since now
both parent and session engine are now merging the lists.
OK denis@


# 1.384 15-Mar-2019 claudio

Set all default values in init_config in parse.y and remove the special
ones in session.c. Adjust printconfig a bit to only show non default values
and move mrt_mergeconfig into merge_conifg where it kind of belongs.
OK benno@


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.383 09-Mar-2019 claudio

Unbreak 'announce inet none' which was actually clearing way too much.
'announce inet none' should only clear AFI/SAFI pairs where the AFI is
inet.
OK benno@


# 1.382 07-Mar-2019 claudio

Do a better job at cleaning up the config on shutdown. Remove bits that
were missed before (e.g. network related objects). This helps to detect
memory leaks.
Start using new_config() and free_config() in all places where bgpd_config
structure are used. This way the struct is properly initialised and cleaned
up. Introduce copy_config() to only copy the values into the other struct
leaving the pointers as they were.
Looks good to benno@


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.381 27-Feb-2019 claudio

Fix export none. none became a keyword some time ago and so this broke.
Switch also default-route to a keyword and remove the old 6.3/6.4 announce
compat code.
Reported by florian@
OK benno@


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.380 26-Feb-2019 claudio

Add support for '*', local-as and neighbor-as for ext-community matching
and setting. This allows rules like:
ext-community * * # delete any ext-community
ext-community ovs * # delete any ext-community of specified type
ext-community rt 1.2.3.4:*
and
ext-community rt 65001:local-as
ext-community rt local-as:11111

Note: Sometimes the type of the ext-community is underspecified when using
wildchars or expands. So 'ext-community rt *' or 'ext-community soo *' will
match for any of the 3 possible types (2-byte AS, 4-byte AS and IP address).
If local-as/neighbor-as is used as an expand of as-number like
ext-community rt local-as:11111
then bgpd will default to the 4-byte AS type to encode the community.

OK benno@


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.379 18-Feb-2019 claudio

Add stdlib.h since bsearch and strtoul need it.


# 1.378 18-Feb-2019 claudio

Initialize type and subtype because modern gcc complains about it.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.377 18-Feb-2019 claudio

Drop netmpls/mpls.h include, not needed here.


# 1.376 18-Feb-2019 claudio

Use (unsigned) long long instead of (u_)int64_t since that drops the
need to do casts for printf.


# 1.375 18-Feb-2019 claudio

Do not depend on the length field of struct sockaddr instead pass the
length to the various functions needing it. Helps portability.
OK benno@


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.374 15-Feb-2019 claudio

Remove stray ',' at end of a yacc rule. Noticed by bison.


# 1.373 15-Feb-2019 claudio

Use the posix version of betoh64() which is spelled be64toh() this is more
portable.


# 1.372 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.371 12-Feb-2019 claudio

Move the yyerror in case get_mpe_config fails. If bgpd -n is used just
ignore the error and move on. This helps regress tests.


# 1.370 11-Feb-2019 claudio

The definition of VPNs in bgpd was never super elegant. The 'depend on
mpeX' config was a bit redundant. Also to make it more flexible (e.g. having
more than one mpeX interface per rdomain the syntax was changed.

To make this possible especially the network distribution logic had to be
adjusted and cleaned up. This should in general make network statements
well defined and conflicts between 'network A.B.C.D/N' and e.g. 'network static'
are handled in a well defined way ('network A.B.C.D/N' has preference).

With and OK dlg@, OK denis@


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.369 04-Feb-2019 claudio

Implement as-override, a feature where the neighbor AS is replaced by the
local AS in AS paths. This is sometimes needed in bigger transport networks
where private AS numbers are used in multiple locations.
The implementation is done using a filterset which modifies the AS path -
somewhat inspired by the set attribute code. Setting as-override yes will add
match from <neighbor> set { as-override }
to the start of the filter rules. Since this is filters the Adj-RIB-In still
holds the original path and so reloads changing the setting just work.
With and OK markus@


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.368 30-Dec-2018 denis

add support for IPv6 VPN routes

The kernel bits are missing as of now. With input from claudio@ and kn@

OK claudio@


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.367 28-Dec-2018 denis

set conf.capabilities.mp to 0 by default

OK claudio@


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.366 19-Dec-2018 claudio

Fold ext-communities into filter_community so that bgpd can match
multiple ext-communities at the same time as well. Additionally this fixes
parsing some of the ext-community types. Now all communities are handled
by one common struct.
OK benno@ plus some input from denis@


# 1.365 06-Dec-2018 claudio

Implement a simple ruleset optimizer. All it does is merge filter rules that
only differ in the filter sets. Since this is still rather common it is able
to reduce the number of rules by 5% on an autogenerated config.
OK job@


# 1.364 28-Nov-2018 claudio

Start reworking community handling. Merge standard communities and large
communities into one filter_community struct and allow it that more then
one community can be used in filter rules (currently up to 3).
Also rework the code handling bgpctl show rib commands. The special IMSG
types for the various filters are gone and the code is in general simpler.
OK job@, phessler@


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.363 18-Nov-2018 claudio

Use correct name when printing the error message that a network prefix-set
is not found. Fixes crash reported by Tom Smyth.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.362 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.361 29-Sep-2018 claudio

Implement origin validation in bgpd. This introduces two new tables, the
roa-set for RPKI based origin validation and a origin-set which allows to
lookup a source-as / prefix pair.
For RPKI a config can be built like this:
roa-set {
165.254.255.0/24 source-as 15562
193.0.0.0/21 maxlen 24 source-as 3333
}
deny from any ovs invalid
match from any ovs valid set community local-as:42
match from any ovs not-found set community local-as:43
Origin sets are similar but only match when the source-as / prefix pair is
valid.
match from any origin-set ARINDB set community local-as:44
Committing this now so that further work can be done in tree.
OK benno@, job@


# 1.360 27-Sep-2018 benno

unbreak "inet" and "inet6" aliases in filters after rev. 1.333
ok claudio@


# 1.359 21-Sep-2018 claudio

Both AS 23456 and AS 0 are reserved and can nor be used. Extend check for
AS 0 and adjust yyerror message to print the right number.
With input and OK denis@


# 1.358 21-Sep-2018 claudio

better yyerror messages. "syntax error" is generally not very helpful.
OK denis@


# 1.357 21-Sep-2018 claudio

Move setting of the PREFIXSET_FLAG_OPS higher up since prefixset_item rule
is now also used by roa-set. Also set the prefix operation for roa-set
items to OP_NONE since that what it actually needs to be.


# 1.356 21-Sep-2018 claudio

Implement code to parse, print and reload roa-set tables.
This is sharing a lot of code with prefixset which makes all a bit easier.
A roa-set is defined like this:
roa-set "test2" {
1.2.3.0/24 source-as 1,
1.2.8.0/22 maxlen 24 source-as 3
}
No support for acting on this data yet.
Put it in deraadt@, OK benno@, input and OK denis@


# 1.355 20-Sep-2018 claudio

Split up as_set into a set_table and an as_set. The first is what does
the lookup and will now also be used in roa-set tries. The as_set is glue
to add the name and dirty flag. Add an accessor to get the set data so
that the imsg sending and printing can be moved into the right places.
This is done mainly because roa-sets need similar but slightly different
versions and making the code more generic is the best way fixing this.
OK benno@


# 1.354 20-Sep-2018 claudio

Switch prefixset to an RB_TREE instead of a SIMPLEQ. This allows to trigger
on duplicates (which are only reported) but is needed as a preparation step
for roa-sets.
OK benno@ denis@


# 1.353 14-Sep-2018 claudio

Extend as_set to allow for different sized objects to be added. The only
requirement is that the first value of the struct is a 32bit ID which is
used in the bsearch. This allows to add more than just as numbers to a
set. as_set_match now returns a pointer to this data or NULL if not found.
OK benno@


# 1.352 13-Sep-2018 claudio

Similar to as-set factor out the code to create a prefix-set into a function.
Makes all a bit nicer and as an added bonus fixes a memory leak.
OK phessler@


# 1.351 13-Sep-2018 claudio

ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and kind of an or-longer case with an upper limit.
So these two prefix statements are equivalent:
prefix 10.0.0.0/8 prefixlen 8 - 24
prefix 10.0.0.0/8 maxlen 24
While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
OK phessler@


# 1.350 10-Sep-2018 benno

use filterset_move() like all other network statements. It checks for
source == NULL, avoiding a possible crash introduced yesterday.
ok claudio@


# 1.349 09-Sep-2018 claudio

Allow for empty as-set and prefix-set definitions by adding explicit rules
for those because shift/reduce issues in the list with optional commas.
OK benno@


# 1.348 09-Sep-2018 claudio

Shut up a gcc warning about uninitialized use of min & max by adding a default
case in the switch statement. Found by denis@ and fix proposed by sthen@


# 1.347 09-Sep-2018 claudio

Can not allow empty as-set and prefix-set blocks right now. This produces
shit/reduce confilcts which need to be resolved first.


# 1.346 09-Sep-2018 claudio

Remove another optnl. In general we no longer support a newline between
the keyword and "{". In this case it is 'set {'.
Newlines afterwards are accepted.


# 1.345 09-Sep-2018 claudio

Bad merge, change a optnl to comma since that is what we want there.


# 1.344 09-Sep-2018 claudio

Rework the parser a bit to be more sane when it comes to newline and comma
handling. In expansion lists we want that commas and newlines are allowed
but optional. In the neighbor, group and rdomain blocks statements need to
be newline separated but neighbor 192.0.2.3 { descr "test-peer" } is allowed.
OK sthen@ benno@


# 1.343 09-Sep-2018 claudio

Write asset as as_set since the other word is already used in English.
benno@ agrees, OK compiler


# 1.342 09-Sep-2018 benno

Add network prefix-set <name> syntax to announce networks in a prefix-set.
feature discussed with deraadt@ and job@, ok claudio@


# 1.341 08-Sep-2018 benno

implement or-longer filter op for prefix-sets. Allows one two write rules like
deny from any prefix-set mynetworks or-longer
ok claudio, feature discussed with job and deraadt


# 1.340 08-Sep-2018 claudio

More BGPD_OPT_NOACTION checking to make regress happier.


# 1.339 08-Sep-2018 claudio

If BGPD_OPT_NOACTION is set don't check that the rdomain exists.
This makes it possible to use bgpd -nv in regress with unknown rdomains.


# 1.338 08-Sep-2018 claudio

Change the way we parse prefix-sets so that newlines are allowed in more
places and so prefix-sets look a lot better. Currently commas are not allowed
but they will come back soon.
OK benno@


# 1.337 07-Sep-2018 benno

remove unused function find_prefixsetitem(), ok claudio@


# 1.336 07-Sep-2018 benno

allow as4number_any in as-sets. Otherwise you cant filter bogon as'es.
ok claudio@


# 1.335 07-Sep-2018 miko

replace malloc()+strlcpy() with strndup() in cmdline_symset().

"looks good" gilles@ halex@


# 1.334 07-Sep-2018 claudio

Implement as-set a fast lookup table to be used instead of long list of
AS numbers in source-as, AS and transit-as filterstatements. These table
use bsearch to quickly verify if an AS is in the set or not.
The filter syntax is not fully set in stone yet.
OK denis@ benno@ and previously OK deraadt@


# 1.333 05-Sep-2018 claudio

Implement most prefixlen operations as OP_RANGE (prefixlen A - B).
Simplify the RDE logic this way and make it possible to load such ranges
into a much faster lookup trie for prefix-sets.
When printing the config bgpd tries to use the nices way to express the rule:
e.g. match from any prefix 18.0.0.0/8 prefixlen 8 - 32
becomes match from any prefix 18.0.0.0/8 or-longer
Apart from that there is no user visible change because of this.
OK sthen@


# 1.332 05-Sep-2018 claudio

Change the way as_compare() and aspath_match() handle 'neighbor-as'. Instead
of doing the condition before calling aspath_match() just pass the neighbor-as
down to as_compare() which then has all needed data for the lookup. While
doing this also remove one of the as fields in struct filter_as since the
min/max fields can be reused for unary operations.
OK denis@ phessler@


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.331 27-Aug-2018 claudio

If the maximum for a community is defined via the large flag then
this maximum should also be passed to strtonum() instead of UINT_MAX
or the error handling does not work.


# 1.330 27-Aug-2018 claudio

merge_filterset() needs to produce a stable sorted filterset to make sure
the RDE can compare the sets on reload and skip those that did not change.
For large communities the check is wrong and incomplete, replace it with
a simple memcmp() of the structs which will result in a stable order.
OK phessler@


# 1.329 08-Aug-2018 claudio

Merge getcommunity() and getlargecommunity() into one function that
takes a flag if it is large or not. Makes code more reusable.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.328 11-Jul-2018 benno

add option "network ... priority number" to announce prefixes from the
kernel routing table selected by priority.
For example to import all ospfd/ospf6d routes into bgp.
tested by remi@
ok remi@ henning@ and maybe a little claudio@


# 1.327 10-Jul-2018 benno

You can run multiple copies of bgpd in seperate rdomains.

However, the processes will see each others route messages. Some
structures are not initialized correctly for that, causing at least
useless log messages.

This is an attempt to use the default_tableid where its needed.

A few hardcoded uses of rtable 0 remain.

ok claudio@


# 1.326 10-Jul-2018 benno

dont let rtable number overflow,
we only support up to RT_TABLEID_MAX rtables
ok henning@, claudio@, phessler@


# 1.325 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.324 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.323 13-Jun-2018 job

Provide backwards compatibility for some of the announce directives

OK sthen@


# 1.322 13-Jun-2018 claudio

Deprecate announce (all|self|none|default-route)
The announce keyword was overloaded and confused a lot of operators, time
to clean it up and while there incorporate RFC8212 guideline for propagation.
- `announce all` is the new default but the default deny filter will
make sure that by default nothing is leaked
- `announce self` is no more and results in syntax error
- `announce none` is now `export none`
- `announce default-route` becomes `export default-route`
- the filters are switched to a default deny rule both incoming and outgoing

You most certainly need to adjust your config!

Best is to change the config in advance by using `announce all` explicitly on
all neighbors and adding `deny from any` and `deny to any` at the start of
your filters and adjust the rest of the filters to still produce the same
result. `bgpd -nv -f bgpd.conf ` and `bgpctl show rib out nei foo` are good
tools to verify the changes.
Lots of discussions with job@, deraadt@, sthen@
OK job@


# 1.321 11-Jun-2018 denis

Fix an off-by-one line count when using include statements.

Thanks to otto@ for the initial diff.

OK benno@


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.320 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.319 10-Feb-2018 benno

Add prefix-sets, lists of prefixes which can be used in place of a
prefix in a filter rule. Initial idea hashed out with job@ in Toronto.
This is WIP, i'm commiting it now so we can work on it in the tree.
ok florian@ claudio@


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.318 05-Feb-2018 claudio

Add a comment why it is OK to set the tableid to 0 for Adj-RIB-In/Out.
Requested by henning@


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.317 04-Feb-2018 claudio

Clenaup RIB handling in the RDE. Introduce some defines for Adj-RIB-In and
Adj-RIB-Out and use them consistently. Makes code easier to read.
OK benno@


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.


# 1.316 19-Oct-2017 jsg

don't try to print uninitialised memory as a string in error paths
ok deraadt@ claudio@


Revision tags: OPENBSD_6_2_BASE
# 1.315 21-Aug-2017 phessler

When 'enforce neighbor-as no' is set, don't do a config-time check for the neighbor-as, as it is dynamic.


# 1.314 12-Aug-2017 phessler

allow filter rules to be written that affect ibgp or ebgp neighbors

discussed with henning@
OK claudio@, benno@, job@


# 1.313 11-Aug-2017 claudio

softreconfig in and out are on by default for ever and machines now have
enough memory that it does not make sense to provide these knobs anymore.
They just make the code more complex for no much gain.
OK phessler@, benno@


# 1.312 26-Jun-2017 phessler

let admins set an unknown well-known community

from Job Snijders
ok phessler@ benno@


# 1.311 26-Jun-2017 phessler

add support for the "graceful shutdown" well-known community as described
in draft-ietf-grow-bgp-gshut

from Job Snijders
ok phessler@ benno@


# 1.310 26-Jun-2017 phessler

allow setting localpref to 0

from Job Snijders
ok phessler@ benno@


# 1.309 31-May-2017 claudio

Too vs To. Found by Denis Fondras openbsd (at) ledeuns (dot) net


# 1.308 31-May-2017 claudio

Rework the way we do extended communities (mainly in the parser) and update
the IANA table to a somewhat more complete list. This includes BGP Prefix
Origin Validation State support via the ext-community ovs keyword.
OK henning@ benno@ based on a diff by Job Snijders


# 1.307 29-May-2017 phessler

remove the file permission check for bgpd.conf

OK deraadt@, henning@, sthen@, and everyone who has ever been annoyed


# 1.306 28-May-2017 henning

so far, bgpd was hardcoded to use rtable 0 for nexthop verification.
instead, use the rtable bgpd was started in (route -T <n> exec / rc.d
daemon_rtable) for nexthop verification and as default Adj-RIB-In and
Loc-RIB. This allows multiple bgpds in different rdomains on the same
machine - bgp router virtualization if you like buzzwords.
initial version written under contract more than a year ago, it took us
a while to wrap our brains around the bgpd <-> rdomain interactions -
1) RIBs, 2) nexthop verification and 3) tcp sockets.
ok & input phessler claudio benno


# 1.305 27-May-2017 phessler

Allow an administrator to disable the bgp loop detection algorithm,
which is useful in very limited situations.

Angry dragons and grues will hunt for you, if you use it.

OK claudio@ sthen@ benno@


# 1.304 27-May-2017 benno

allow only one network <prefix> statement per for the same prefix.
ok florian@ phessler@


# 1.303 27-May-2017 phessler

Allow OpenBGPD to selectively choose which local ASN to use per-peer.
This is intended to be used for ASN migrations, not for permanent use.

You MUST use filters to protect yourself from receiving your own routes.
There be dragons and grues.

OK claudio@ benno@


# 1.302 27-May-2017 phessler

allow us to use 'local-as' in the filter language

"match in from any set community local-as:neighbor-as"

OK claudio@


# 1.301 26-May-2017 phessler

AS 0 is special and should be considered an error.

Drop the session if it shows during OPEN or CAPA, or mark as invalid if
it is part of an Update.

required by RFC 7607

man page OK jmc@
OK florian@ benno@ claudio@


# 1.300 26-May-2017 phessler

Expand RIB names in groups

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


# 1.299 26-May-2017 phessler

Allow nested {} in prefix lists.

Diff from Denis Fondras, many thanks!

OK claudio@ phessler@


Revision tags: OPENBSD_6_1_BASE
# 1.298 22-Feb-2017 renato

Add missing htonl for IPsec SPI.

Also, do not allow to configure SPI values in the 0..255 range. RFC 4302
and RFC 4303 say the following:
"The set of SPI values in the range 1 through 255 are reserved by the
Internet Assigned Numbers Authority (IANA) for future use; a reserved
SPI value will not normally be assigned by IANA unless the use of the
assigned SPI value is specified in an RFC. The SPI value of zero (0)
is reserved for local, implementation-specific use and MUST NOT be
sent on the wire".

ok and tweak benno@


# 1.297 25-Jan-2017 claudio

Flag the Loc-RIB with F_RIB_LOCAL so we can remove one ugly hack somewhere else


# 1.296 24-Jan-2017 benno

sync log.c from relayd et al to bgpd.

there is still a little difference regarding handling of the verbosity
value that will be handled later.

ok claudio@ florian@


# 1.295 18-Jan-2017 phessler

while a u_int is large enough for 32bit-asns, it is not big enough for
some of the magic values we use to indicate '*' or neighbor-as.

fixes "allow from any large-community neighbor-as:*:*"


# 1.294 13-Jan-2017 phessler

Add support for draft-ietf-idr-shutdown

BGP state = Idle, marked down with shutdown reason "goodbye, we are
upgrading to openbsd 6.1", down for 00:00:17

developed by Peter van Dijk <peter.van.dijk@powerdns.com> and Job
Snijders <job@ntt.net>, thank you!

OK benno@


# 1.293 05-Jan-2017 krw

Replace hand-rolled for(;;) emptying of 'symhead' TAILQ with more
modern TAILQ_FOREACH_SAFE().

No intentional functional change.

ok millert@ bluhm@ gilles@


# 1.292 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.291 26-Dec-2016 jca

Typo, "more then" -> "more than"


# 1.290 14-Oct-2016 phessler

Add support for draft-ietf-idr-large-community

Joint work with Job Snijders, many thanks!
OK benno@ deraadt@


# 1.289 05-Oct-2016 phessler

Let bgpd announce routes based on a route-label.

OK henning@ benno@


Revision tags: OPENBSD_6_0_BASE
# 1.288 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.287 03-Jun-2016 benno

Add operators =, !=, - (range), >< (exclsive range) to the as-path
filters (AS, peer-as, source-as, transit-as).

Add a use case (block illegal AS numbers) to the bgpd.conf example.

feedback from claudio, sthen, florian,
ok florian@ phessler@


Revision tags: OPENBSD_5_9_BASE
# 1.286 27-Oct-2015 mmcc

calloc -> malloc when the memory is immediately overwritten with memcpy.

ok claudio@


# 1.285 22-Oct-2015 reyk

Revert revision 1.282:
"Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option."

This broke the grammar by introducing shift/reduce errors.

OK phessler@


# 1.284 11-Oct-2015 phessler

standardize a community that has been independently created by nearly
every single AS on the planet: the blackhole

OK benno@, claudio@, sthen@


# 1.283 21-Sep-2015 phessler

Let us log all updates sent from an individual peer. Since this can be
applied to a group, also let us disable logging on a sub-member of the
group. Very handy for debugging naughty peers on a router with multiple
peers.

OK benno@


# 1.282 21-Sep-2015 phessler

Allow for empty blocks for peers. While this is bad style for permant
use, this is very nice to temporarily disable a peer option.

OK sthen@ benno@


Revision tags: OPENBSD_5_8_BASE
# 1.281 16-Jul-2015 claudio

Next round of config cleanup. Move various lists into the bgpd_config struct.
This is the next step to better split parsing and merging the config.
OK benno@


# 1.280 26-Apr-2015 benno

mlarkin asks "bgpctl checks the length of the control socket path to
make sure it fits. When browsing around last night I saw that bgpd
does not. Any reason it shouldn't? Please commit"

Add a check in parse.y to check this when reading the configuration.
ok phessler@ henning@


# 1.279 25-Apr-2015 phessler

allow us to write rules that match directly on the peer AS

...
allow from AS 1 prefix 192.0.2.0/24
...

Also adjust the IRR ruleset output to include the declared peer AS,
instead of hoping they listed their neighbor IP address!


OK benno@
older version OK: claudio@ henning@


# 1.278 14-Mar-2015 claudio

rename rde_free_filter() to filterlist_free() and start using it outside
of the RDE to free the filterlists. Also refactor common code to merge
filterlists into its own function. Makes the code look nicer.


# 1.277 14-Mar-2015 claudio

Move the command line options (mainly -d and -v) out of struct bgpd_config
into a own flag field since these can't be modified via a config reload.
OK henning@ benno@ before lock


# 1.276 14-Mar-2015 claudio

Move the code that adjust FIB priority when changed during a config reload
from the parsing function to the merge_config function where it belongs.
OK henning@ benno@ before lock


Revision tags: OPENBSD_5_7_BASE
# 1.275 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.274 03-Nov-2014 bluhm

Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK benno@ doug@ claudio@


# 1.273 02-Nov-2014 doug

Add gcc format attributes to parse.y's yyerror() for bgpd.

Fix some of the format characters in yyerror calls: %u -> %zu, %lld -> %u

ok claudio@


Revision tags: OPENBSD_5_6_BASE
# 1.272 02-May-2014 deraadt

spelling; Denis Fondras


Revision tags: OPENBSD_5_5_BASE
# 1.271 22-Jan-2014 henning

relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.270 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.269 13-Nov-2013 florian

Knob to set priority with which bgpd inserts routes into the kernel
routing table. Need for it in "special" setups pointed out by
Loic Blot (loic.blot _AT_ unix-experience _DOT_ fr) on tech.
OK benno, henning


# 1.268 19-Oct-2013 claudio

Merge the prefix and prefixlen filter bits into one filter. Change the
filter expansion so that rules are grouped by prefixes last. The RDE will
then be able to optimize the rules into table lookups but that is a later
step. As additional goodies it is now possible to use inet and inet6
on their own and or-longer can be used as a shorthand for prefixlen >= len.
OK henning@ sthen@ florian@


# 1.267 27-Sep-2013 sthen

typo in macro name; no md5 change


Revision tags: OPENBSD_5_4_BASE
# 1.266 11-May-2013 benno

change mrt rib dump ReopenTimerInterval from time_t to int. Intervalls
don't need to scale to 64 bits in this universe.
ok claudio@ & florian@


Revision tags: OPENBSD_5_3_BASE
# 1.265 13-Nov-2012 claudio

Allow filtering based on the NEXTHOP attribute. This allows to build rules
like: allow from any nexthop neighbor (to allow only prefixes that use the
routers IP address as nexthop). Lots of testing, input and OK florian@


# 1.264 23-Sep-2012 claudio

Enable graceful restart by default. The only way to find out if it works for
real. After discussion with sthen@, henning@ and deraadt@.
It can be disabled per neighbor with "announce restart no".


# 1.263 12-Sep-2012 claudio

Better graceful restart support (implementing more then just the EoR record).
This implements only the "Restarting Client" bits of the RFC -- in other
words bgpd will keep the FIB when the client restarts but it will not do GR
when restarting itself. The capability is still off by default (you need
"announce restart yes" to enable it).
Tested by Anders Berggren. OK sthen@


Revision tags: OPENBSD_5_2_BASE
# 1.262 13-Jul-2012 claudio

Make sure that set med 0 is ACTION_SET_MED and not relative. Fixes
set med 0 and Hennings iBGP sessions. OK henning@


# 1.261 12-Apr-2012 claudio

The ebgp flags is just a truth value and it is better to not == 1 compares.
OK henning@ sthen@


Revision tags: OPENBSD_5_1_BASE
# 1.260 17-Sep-2011 claudio

Implement new mrt table dump format as specified in draft-ietf-grow-mrt.
Tested with IP and IPv6 sessions and against the libbgpdump parser.
OK henning@


Revision tags: OPENBSD_5_0_BASE
# 1.259 01-May-2011 claudio

On reload the filtersets attached to a network need to be moved to the
existing network element. First free the old filterset and then move
the new on top of it. This solves the reload issue with changing network
statements. OK henning@


Revision tags: OPENBSD_4_9_BASE
# 1.258 02-Sep-2010 sobrado

remove trailing spaces and tabs from source code; no binary changes
(verified by both sthen@ and me).

ok sthen@; "just commit it" claudio@


Revision tags: OPENBSD_4_8_BASE
# 1.257 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.256 27-Jun-2010 claudio

Instead of specifying the control sockets on the command line have them
in bgpd.conf. This allows to add/modify restricted control sockets on runtime.
Feature request by a few people how often forgot to add -r path when restarting
bgpd (including myself).
NOTE: this removes the -s and -r arguments from bgpd so pay attention when
updateing.
jajaja sthen@, OK henning@


# 1.255 17-May-2010 claudio

Implement two new filters, max-as-len and max-as-seq. The first is limiting
the length of an AS path (matches if the path is longer then the specified
lenght) the second matches when a sequence of the same AS number is longer
then the specified length).
max-as-len is good to protect crappy comercial bgp boxes from other crappy
comercial bgp boxes. max-as-seq was a feature request from SwissIX and maybe
EuroIX to find and filter prepends.
Additinal testing and OK sthen@


# 1.254 17-May-2010 claudio

Last bits of MPLS VPN support. Hook kernel routing tables and RIB together.
This adds a bit of new config to specify the mapping between an rdomain and
the BGP MPLS VPN instance, example:
rdomain 1 {
descr "CUSTOMER1"
rd 65003:1
import-target rt 65003:3
export-target rt 65003:1
depend on mpe0
network 192.168.224/24
}
The "depend on mpe0" is a but ugly but for now this is the quickest way to
figure out which interface bgp should use to insert the MPLS routes.

A big side-effect of this diff is that networks are now internally
distributed through kroute.c.
This needs some kernel changes that will follow hopefully soon.
OK henning@


# 1.253 03-May-2010 claudio

Make it possible to load multiple routing tables at the same time and use
those for alternate RIBs. This allows to use "rde rib TESTIT rtable 1".
NOTE: nexthop verification has changed for alternate tables. For now
nexthop will only be verified against the main routing table (id 0).
Because of this "nexthop qualify via bgp" may now compare the nexthops
against bgpd routes from a different RIB.
Tested by sthen@, OK to move on by henning@


# 1.252 28-Apr-2010 claudio

Allow neighbor-as in AS filter statements like:
match from any source-as neighbor-as set localpref 1000
OK henning@


# 1.251 26-Apr-2010 claudio

Fix some memory leaks on config reload failure and move one particular
cleanup loop to parse.y where it belongs.
OK henning@


# 1.250 31-Mar-2010 claudio

network static and network connected have been superseded by network inet
static and network inet connected a long time ago. It is time to remove
the old compat code.


Revision tags: OPENBSD_4_7_BASE
# 1.249 05-Mar-2010 claudio

Allow to filter for ext-community attributes. Currently only perfect matches
work but that's already better then nothing. OK sthen@


# 1.248 13-Jan-2010 claudio

Add support for BGP MPLS VPN aka RFC 4364. This is only the RDE part so
that it is possible to use OpenBGPD as a route-reflector for VPNv4.
Some clean up of the BGP MP code so that multiple protocols are easier
supported. kroute/kernel support not yet done but comming.
OK henning@, reyk@


# 1.247 11-Jan-2010 deraadt

lex <=, >=, !=, and >< into a single token for correctness and to reduce the
lookahead in the parser
ok henning


# 1.246 16-Dec-2009 claudio

Implement "set ext-community [delete] subtype key:value" to set and delete
extended communities as specified in RFC 4360. No matching implemented yet
and stuff like * and neighbor-as are neither supported but will be soon.
Looks good henning & sthen, manpage fixed by jmc


# 1.245 09-Dec-2009 claudio

parsecommunity() always works on a struct filter_community. So pass a
pointer to the struct instead of two int pointers.


# 1.244 09-Dec-2009 claudio

parsecommunity() does not allow to set unknown well-known communities.
So there is no need to check that again. Switch a USHRT_MAX to
COMMUNITY_WELLKNOWN to make the compare clearer, the values are the same.


# 1.243 08-Dec-2009 claudio

Big AID change part two. This changes the mp capability into an array of
flags. This makes a lot of code much easier since the comparison is now
trivial. Additionally calculate the negotiated capabilities for a session
in the SE and pass that and only that to the RDE. This makes the decisions
in the RDE a lot easier. OK henning@


# 1.242 06-Dec-2009 claudio

Doh, switch src and dst in memcpy calls or the wrong thing gets copied.
For some reasons memcpy has the argument reversed - grmbl.
Found the hard way by Insan Praja.


# 1.241 01-Dec-2009 claudio

Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.


# 1.240 26-Nov-2009 henning

support for set origin; based on an initial diff from
Sebastian Benoit <benoit-lists at fb12 dot de> who also tested this version
claudio ok


# 1.239 11-Nov-2009 claudio

Plug two memory leaks in error pathes. Found by parfait. OK henning, jsg


# 1.238 13-Oct-2009 claudio

Disable graceful restart for now. The EOR marker is sent in the wrong place
and fixing this is not a two liner. Will be enabled again when I found out
how to fix this.


# 1.237 06-Oct-2009 claudio

Add config knobs to enable/disable individual BGP capabilities per neighbor.
e.g. announce refresh no. With this be more aggressive when announcing our
capabilities and enable all of them by default. If there are troubles with
some neighbors adding the following config lines should bring you back
to the old behaviour:
announce refresh yes # was already on by default
announce restart no
announce as-4byte no # was only set on sessions to peers with 4byte AS nums
OK henning and sthen


# 1.236 04-Sep-2009 claudio

Make sure that a proper syntax error is produced when something else then
yes or no is used in a yes/no token. OK henning


# 1.235 04-Sep-2009 claudio

Use the address familiy of the neighbor IP to decide which MP type to use.
IPv4 session will still default to only announce inet unicast but now
IPv6 session will by default use announce inet6 unicast. The defaults
can be overridden on groups and in the neighbor itself but this new
behaviour is way more sane then the old one. OK henning, sthen


# 1.234 31-Aug-2009 claudio

Use UINT_MAX instead of ASNUM_MAX and get rid of this mostly useless define.


# 1.233 03-Aug-2009 claudio

Make announce "self" work like all others (self is a bit special because
it's a keyword but "self" is not). OK henning@


# 1.232 20-Jul-2009 claudio

Flag added RIBs as F_RIB_NOFIB | F_RIB_NOEVALUATE in the no-eval case even
though F_RIB_NOEVALUATE implicitly includes F_RIB_NOFIB.


Revision tags: OPENBSD_4_6_BASE
# 1.231 06-Jun-2009 claudio

Some preliminary filter magic to support multiple RIBs on the filters.
It is ugly but does the trick for now. Filters will be rewritten anyway.
The rib specifier only makes sense on from rules. e.g. deny rib OMG from any


# 1.230 06-Jun-2009 claudio

Only the main Loc-RIB should update the FIB for now. So introduce a
F_RIB_NOFIB flag and apply it on all RIBs that are not F_RIB_NOEVALUATE.


# 1.229 05-Jun-2009 claudio

Don't call the main RIB DEFAULT but Loc-RIB. Makes more sense.


# 1.228 05-Jun-2009 claudio

Make it possible to bind peers to a specified RIB. Now only filters and
bgpctl are missing to have full support of multiple RIBs.


# 1.227 04-Jun-2009 claudio

Make mrt understand alternate RIB plus remove some other static rib references.
There is still a problem with the mrt dumps because we only allow one in the
RDE. This needs some additional work.


# 1.226 04-Jun-2009 claudio

Add "rde rib <name>" to the config and allow the rde to use these other RIBs.
Still a bit hackish, reload is missing and printconf as well. Looks good h@


# 1.225 27-May-2009 reyk

add an option to change the "connect-retry" timer which defaults to 120s.
this can be used to decrease the failover time in specific carp'ed
IBGP setups.

ok henning@


# 1.224 23-Apr-2009 sthen

allow bgpctl and bgpd.conf to contain 32-bit ASN written in ASPLAIN
format (RFC5396). ok claudio@ henning@


# 1.223 31-Mar-2009 tobias

Fixed memory leaks which would occur if the second of two memory
allocations fails.

looks right deraadt, krw
ok henning


# 1.222 26-Mar-2009 henning

argh, do not reuse the global trans_as flag to be applied to the peer
specific or we had to widen the peer specific flags without need.
defien PERRFLAG_TRANS_AS instead and use that


# 1.221 22-Mar-2009 henning

make transparent-as yes|no settable peer neighbor with the global setting
acting as default.
per-neighbor requested by arnold nipper @ decix, ok claudio


# 1.220 18-Mar-2009 claudio

Introduce local_as in the peer config. This allows per peer local AS and
simplifies some code because it is possible to get the local AS from the
peer struct. Local AS needs more patching to work correctly though.
OK henning@


Revision tags: OPENBSD_4_5_BASE
# 1.219 16-Feb-2009 sthen

typo in error message; "bigger that" -> "bigger than"


# 1.218 17-Oct-2008 henning

bring in the findeol() fix from pfctl. list of affected parsers by sthen


Revision tags: OPENBSD_4_4_BASE
# 1.217 08-Jul-2008 claudio

Use correct format string specifier for int argument. Don't try to print it
as string. Fixes crash seen by Peter Bristow. "obviously ok" henning@


# 1.216 15-Jun-2008 claudio

Allow bgpd to delete more then one community per filter rule. Fixes PR5807
tested by Raphael Ho long time ago.


Revision tags: OPENBSD_4_3_BASE
# 1.215 26-Feb-2008 mpf

Have popfile() also close the main config file,
but only do the final popfile call after yyparse() is done.
This also fixes config reload on SIGHUP for some daemons.

Spotted by otto@. OK deraadt@


# 1.214 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.213 20-Oct-2007 pyr

ntpd and bgpd's turn to behave like the others.
ok henning@


# 1.212 16-Oct-2007 mpf

Allow '=' to end a number in all lexers.
Requested and OK deraadt@


# 1.211 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.210 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.209 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.208 13-Sep-2007 claudio

Move parser to use NUMBER as all other parse.y do know. A bit tricky because
all the relative metrics need some special handling. OK henning@ deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.207 31-May-2007 claudio

Init community in get_rule() to COMMUNITY_UNSET. get_rule() is called when
set is used inside neighbor or group statements and the result was that
these rules no longer machted everything. Problem found by Jon Morby.
Please commit henning@


# 1.206 31-May-2007 claudio

Even so some IX in germany likes to abuse 0 as AS community number we should
not allow anybody to use 65535. That one is reserved for well known
communities. Add in that check again.


# 1.205 28-May-2007 henning

allow matching on communities using 0 in the AS part, that is in use.
that unfortunately means we cannot use 0 for "unset".
ok claudio


# 1.204 23-Apr-2007 claudio

Make bgpd 4-byte AS compatible. All internal representations of AS numbers
are now 4-byte instead of the old 2-byte numbers. The only exception are
communities because they can not be switched. The RDE will inflate and deflate
the ASPATH and AGGREGATOR attributes on demand and create the NEW_ASPATH and
NEW_AGGREGATOR field whenever needed. Both old and new stile sessions are
supported and can be mixed. Currently new stile sessions with the 4-byte AS
number capability turned on are only enabled if one of the AS numbers involved
is a 4-byte one.
This is based on an initial diff by Geoff Huston gih (at) apnic (dot) net
Cleanup, testing and bug-fixes by myself (via AS 3.10).
Currently mrt table dumps are producing incompatible output this will be fixed
afterwards -- this diff is already big enough.

"get it in if you think it is ready" henning@


# 1.203 17-Apr-2007 claudio

Make "network inet connected" work again. inet and inet6 became keywords
some time ago. OK henning@


# 1.202 29-Mar-2007 claudio

Until now prefixlen defaulted to AF_INET if it was used without a prefix.
This makes prefixlen filtering for AF_INET6 unnecessary complex. From now
on if prefixlen is used alone the address family needs to be specified
beforehands via the new inet or inet6 keywords.
Remove an old check so that it is finally possible to filter IPv6 prefixes.
OK henning@


Revision tags: OPENBSD_4_1_BASE
# 1.201 06-Mar-2007 henning

allow filtering on peer-as (leftmost AS in path), ok claudio


# 1.200 22-Feb-2007 henning

KNF


# 1.199 26-Jan-2007 claudio

AS 65535 aka USHRT_MAX is reserved and may not be used so adapt the
range check. Found while hacking on 4-byte AS support.


# 1.198 05-Dec-2006 henning

implement the ttl security hack. since the pc slaves fear the word hack,
they call it "Generalized TTL Security Mechanism" officially, RFC 3682.
manpage with help from jmc


# 1.197 28-Nov-2006 henning

allow bgpd to work on alternate routing tables, claudio ok, jmc manpage help


# 1.196 25-Oct-2006 henning

use strtonum, Pierre-Yves Ritschard <pyr@spootnik.org>


# 1.195 19-Sep-2006 henning

save the parser state in one big struct, and make it interchangable, aka
make the parser restartable. with that implement "include" file support.
makes life a _lot_ easier with filter generation tools. claudio ok


# 1.194 19-Sep-2006 henning

kill useless debug code that somehow snuck in, some 2 years ago...


Revision tags: OPENBSD_4_0_BASE
# 1.193 27-Aug-2006 henning

add code to announce the restart capability according to
draft-ietf-idr-restart. Do not announce actual restart capabilities,
so that this only serves as indicator that we are capable of sending
and receiving the End-of-RIB marker.
leave disabled for now, since the code to actually send the EoR-marker
is currently ifdef'd out (to be fixed soon) and we wanna play safe for
4.0. and juniper doesn't support that capability (which is not a problem
per se) and at the same time has its capability negotiation code completely
fucked up, if a capability is rejected they don't indicate WHICH capability
they reject (which makes that a problem, tho still a small one and we cope).
claudio ok


# 1.192 04-Aug-2006 henning

add "restart" to max-prefix, allows sessions suspended due to reaching
max-prefix to be restarted automagically after a given number of minutes
requested by "Sylwester S. Biernacki" <obeer@obeer.com>, manpage help jmc,
ok claudio


# 1.191 17-Jun-2006 henning

implement carp demotion control for bgpd.
sessions can be configured to modify the carp demotion counter for a
given interface group (usually, "carp", which has all carp interfaces)
when the session is not established. once the session is established for
60 seconds, the demotion is cleared.
this, used correctly, can prevent a bgpd-box which lost all sessions (and
thus has no routes) to be carp master, while the backup has sessions.
thought through and partially hacked on a drive from calgary to vancouver
with ryan, ok claudio


# 1.190 31-May-2006 pat

Plug memory leaks in error path; ok henning@


# 1.189 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.188 26-Apr-2006 claudio

Remove filterset_names from bgpd.h and replace it with a function because
the table was already out of sync now. OK henning@


# 1.187 18-Apr-2006 henning

cannot see the string self in the ANNOUNCE STRING prod any more since
self is a token now


# 1.186 18-Apr-2006 claudio

Fix "announce self" that got broken by "nexthop self". Found by Thomas Bader.
OK henning@


# 1.185 04-Apr-2006 henning

add "set nexthop self", force nexthop to be set to own address even with IBGP
requested & tested Falk Brockerhoff <fb@smartterra.de>, and tony sarendal
tested this too. claudio ok


# 1.184 22-Mar-2006 claudio

Change the way bgpd selects nexthops. Up until now every route was considered
when calculating the nexthop. Now only non BGP routes and not the default
route are used unless forced with the new config options
nexthop qualify via bgp
nexthop qualify via default
This change is required for complex setups e.g. where an additional IGP is
running. OK henning@


# 1.183 07-Mar-2006 claudio

Fix a bug reported by Xavier Beaudouin. On config reloads set parameters
inside group blocks were reset to default values. The problem was that
group ids changed on reload as soon as a new peer was added to one group.
Make sure that group ids remain the same over reloads a similar thing is
already done for peer ids. ok henning@


# 1.182 04-Mar-2006 miod

Typos grab bag of the month, eyeballed by jmc@


Revision tags: OPENBSD_3_9_BASE
# 1.181 10-Feb-2006 claudio

Make it possible to turn suftreconfig in/out on or off. Default is on for
both directions. Manpage update follows. OK henning@


# 1.180 09-Feb-2006 claudio

Implement "set community delete 65001:*" and friends. This will remove
communities from the path attributes. Useful to make sure that the ones you
set later are set by a (evil) peer. OK henning@


# 1.179 02-Feb-2006 claudio

Implement new special community "neighbor-as". neighbor-as is expanded on
the fly to the remote AS of the current neighbor. This can be used to
simplify rulesets in a dramatic way -- going from a script based nightmare
down to a handfull rules. jajajaja henning@


# 1.178 07-Jan-2006 claudio

Add COMMUNITY_NO_PEER to the list of known wellknown communities else it
is not possible to use NO_PEER as community in the config.


# 1.177 29-Nov-2005 claudio

superfluous ; OK henning@


# 1.176 01-Nov-2005 claudio

Sort filter_set with equal type as well. This affects community
attributes and set nexthop. Now the full filter set list is sorted.


# 1.175 01-Nov-2005 claudio

Relative metrics should be stored in relative and not metric. The one
is singed the other not.


# 1.174 01-Nov-2005 claudio

Make sure, that the list of filter_sets is ordered. Makes comparing easier.


# 1.173 01-Nov-2005 claudio

Switch from the per peer filter set list to a filter-only solution.
The default filter_sets are converted into match filter rules that get
evaluated first. Simplifies code massively -- mainly the config reload
part -- and makes softreconfig out a piece of cake. "get it in" henning@


# 1.172 19-Oct-2005 henning

new keyword "down" in neighbor spec, when givenm, the session is not
started on bgpd startup but stays in IDLE. requested by claudio


Revision tags: OPENBSD_3_8_BASE
# 1.171 09-Aug-2005 claudio

Introduce new route decision tunable "rde med compare (always|strict)".
If set to always the med will also be compared between different AS.
The default is strict which is the way the RFC specifies it.
OK henning@


# 1.170 28-Jul-2005 henning

keywords have to be sorted, and I can't sort properly


# 1.169 28-Jul-2005 henning

allow the to be announced SAFIs to be specified per peer, that is part of the
multiprotocol shitz
claudi needs this to proceed with v6 stuff in the RIB, print stuff and
manpage later
from whatthehack, claudio ok, marcm schnell schnell schnell


# 1.168 04-Jul-2005 claudio

New function filterset_cmp() used two compare two struct filter_set for
equality. This function is a bit more complicated than a memcmp() because there
are types that need to be considered equal e.g. ACTION_SET_MED and
ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP
need some special care. OK henning@


# 1.167 04-Jul-2005 claudio

Switch some parser rules from "string" to "STRING". "string" is to greedy
and hides possible typos. e.g. set { rtlabel foo localperf 100 } was a valid
syntax but the result was a route label with name "foo localperf 100".
OK henning@


# 1.166 01-Jul-2005 claudio

Switch filter_sets form SIMPLEQ to TAILQ, needed for upcomming stuff.


# 1.165 29-Jun-2005 claudio

rtlabel support via filter sets. Just use "set rtlabel foobar" in filters
network and neighbor statements and the routes are labeled accordingly.
While doing that fix some mem-leaks by introducing filterset_free() and
remove the free on send option of send_filterset().
This took a bit longer because we need to carefully track the rtlabel id
refcnts or bad things may happen on reloads.
henning@ looks fine


# 1.164 09-Jun-2005 claudio

Change the "network connected|static" statements to "network inet|inet6
connected|static" so that it is possible to distinguish between IPv4 and IPv6
addresses. "network connected|static" is considered deprecated but will be
supported as an alias for "network inet connected|static" for some time (one
release) to simplify upgrades. This also solve a nasty crash when using
"network connected". OK henning@


# 1.163 24-May-2005 claudio

Remove unnecessary error check that is already done in parsecommunity().


# 1.162 28-Apr-2005 claudio

Support for "network connected" and "network static" -- announce all
directly connected respectively all static routes. The list is auto-
matically adjusted as soon as a route changes.
OK henning@


# 1.161 17-Apr-2005 henning

and don't try to free a null set either


# 1.160 17-Apr-2005 henning

fix null pointer deref on filter rules without set part
problem reported by "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.159 13-Apr-2005 claudio

filter_set cleanup. Plug some memleaks and fix an obvious bug in the
network case. OK henning@


# 1.158 12-Apr-2005 claudio

Introduce a per prefix weight. The weight is used to tip prefixes with equal
long AS pathes in one or the other direction. It weights a prefix at a very
late stage in the decision process. This is a nice bgpd feature to traffic
engineer networks where most AS pathes are equally long.
OK henning@


# 1.157 12-Apr-2005 claudio

Fix some yyerror messages. Ja ja, INT_MAX is to small... OK henning@


# 1.156 29-Mar-2005 henning

walk & free network and filter lists after parse errors
ok claudio theo


# 1.155 28-Mar-2005 henning

walk & free peer_l after failed config parsing attempts


# 1.154 23-Mar-2005 claudio

Move the neighbor checking code from merge_config() to neighbor_consistent()
where it belongs. OK henning@


Revision tags: OPENBSD_3_7_BASE
# 1.153 16-Mar-2005 henning

don't try to merge the freshly parsed config into the running one if
we had parser failures...
debugging session with claudio and jason ackley
ok claudio norby deraadt


# 1.152 14-Mar-2005 claudio

Allow to modify the metrics in a relative way by prepending the number with
a '+' or '-'. e.g. set localpref +20. This is another gem from the FOSDEM
lying around on my HD gathering dust. OK henning@


# 1.151 13-Mar-2005 henning

s/to many/too many/, from jmc


# 1.150 11-Mar-2005 claudio

Finally commit the transparent-as and nexthop no-modify stuff I wrote on the
way to FOSDEM. With transparent-as set to ye bgpd will not prepend his own
AS for sent updates. NB the neighbor needs to set "enforce neighbor-as no"
or it will not like the received AS paths. With set nexthop no-modify bgpd
will change the nexthop as done normaly.
OK henning@ man page update with help of jmc@


# 1.149 23-Dec-2004 henning

KNF


# 1.148 23-Nov-2004 claudio

Switch from a single filter_set to a linked list of sets. With this change
it is possible to specify multiple communities. This is also the first step
to better bgpd filters. OK henning@


# 1.147 19-Nov-2004 claudio

For consistency reasons rename struct as_filter to struct filter_as.
OK henning@


# 1.146 19-Nov-2004 claudio

Make "set network 127.0.0.1" work and use = instead of |= for the
blackhole/reject case as $$ is not zeroed. This caused funny results in
merge_filterset(). OK henning@


# 1.145 18-Nov-2004 henning

add an instance of struct capabilities to peer_conf, and inherit
peer->capa.ann from this


# 1.144 11-Nov-2004 claudio

New config statement "rde route-age [evaluate|ignore]". If set to evaluate
the best path selection will not only be based on the path attributes but
also on the age of the prefix. This is an extension to the RFC. The default
is ignore but previously it was implicitly set to evaluate.
OK henning@ man page OK jaredy@ jmc@


# 1.143 05-Nov-2004 henning

memleaks in error pathes, again awesome work from Patrick Latifi


# 1.142 04-Nov-2004 henning

(try to) open the config file earlier, makes the error handling easier in
case we cannot. in fact there was one missing free(), thus this diff
plugs a little memory hole (without real-world relevance I guess).
From Patrick Latifi, thanks!


# 1.141 19-Oct-2004 henning

allow neighbor definitions to depend on interface state.
with this, if a neighbor is configured as dependent on carp0 for example,
the neighbor will remain in state IDLE as long as carp0 is not master.
once carp0 becomes master the session(s) depending on it immediately
go to CONNECT (or ACTIVE, if they're configured passive), reducing failover
time. claudio ok, with some input from ryan as well


# 1.140 28-Sep-2004 claudio

Add prepend-neighbor feature. Prepend the remote-as n times similar to
prepend-self. Only for incomming UPDATEs. OK henning@


Revision tags: OPENBSD_3_6_BASE
# 1.139 24-Aug-2004 henning

don't do the pftable_exists() check if we are running -n, needs root


# 1.138 24-Aug-2004 henning

correctly inherit conf->opts from xconf->opts in parse_config(),
foudn by claudio


# 1.137 24-Aug-2004 claudio

back out rev. 1.136. I commited that unintentionally and it does not work
without other nastier changes in parse.y.


# 1.136 20-Aug-2004 claudio

Grrr. copy paste error. Dump MED and not local-pref. OK henning@


# 1.135 20-Aug-2004 claudio

foobar-AS -> foobar-as as already done in some places. mIXeD cASe keywords
are not fluffy. OK henning@


# 1.134 17-Aug-2004 claudio

Merge set constructs in neighbor statements. This fixes a common problem:
previous sets were cleared by the last one. OK henning@


# 1.133 13-Aug-2004 claudio

Fix minor issues with IPv6 dumps and add a function for dumping the RIB table
protocol independent. This new dump format is not (yet) supported by the
mrtd route_btoa tool. OK henning@


# 1.132 10-Aug-2004 claudio

switch nexthop in struct filter_set form struct in_addr to struct bgpd_addr
OK henning@


# 1.131 05-Aug-2004 claudio

tab at EOL


# 1.130 03-Aug-2004 claudio

deny hilarious prepends. OK henning@


# 1.129 02-Aug-2004 claudio

Fix a possible mem leak and add a missing yyerror(). OK henning@


# 1.128 30-Jul-2004 claudio

Add new announce type "default-route" which will only announce the default
route to the specified neighbor. Idea and OK henning@


# 1.127 28-Jul-2004 henning

allow "set metric" as synonym for "set med", from discussion with & ok claudio


# 1.126 28-Jul-2004 henning

allow prefix lists inside prefix lists


# 1.125 28-Jul-2004 henning

allow AS lists inside AS lists


# 1.124 28-Jul-2004 henning

prevent the filter elements from beeing given more than once


# 1.123 28-Jul-2004 henning

add list expansion for AS in filter rules
actually, it's list expansion on steroids, this works:
deny from any { source-AS { 3320 852 } AS { 4589 174 } }


# 1.122 28-Jul-2004 henning

rework the filter_match production and everything below - fixes
a couple of bugs


# 1.121 27-Jul-2004 henning

add support for {} expansion for prefix in the filter rules, claudio ok


# 1.120 27-Jul-2004 henning

suport macro expansion for peer spec in filter rules
things like
deny from { $peer1 $peer2 } prefix 192.168.0.0/16
are now possible.


# 1.119 13-Jul-2004 jaredy

fix some typos

ok henning otto


# 1.118 05-Jul-2004 henning

implement "set nexthop blackhole" and "set nexthop reject"
blackhole/reject routes will be entered to the kernel for matching ones.
this is intended to be used with the Cymru Bogon Route Server Project
(http://www.cymru.com/BGP/bogon-rs.html) and similar services, claudio ok


# 1.117 03-Jul-2004 claudio

Switch mrt dumping to fd passing. This gives some speed up when extensive
dumping is done. Acctually mrt dumps were broken because of the fd passing.
The nice side effect is a much cleaner code, especially in the parent process.
OK henning@


# 1.116 23-Jun-2004 claudio

Support rfc 3765 which adds a new well known community NOPEER. OK henning@


# 1.115 20-Jun-2004 henning

at least somewhat consistently name the TAILQ_ENTRYs... this confused me
more than once


# 1.114 08-Jun-2004 henning

fix a few memory leaks in error paths and one in the pftable path,
and simplyfy the prefix production error handling slightly
from Mr. Memleak Terminator Patrick Latifi <pat@eyeo.org>, kickass!


# 1.113 06-Jun-2004 henning

rework bgpd's handling of listening sockets. instead of one for each
supported address familiy, keep a tailq of an arbitary number of them.
the new struct listen_addr contains the sockaddr and the fd.
this fixes quite some nasty behaviour which was a consequence of the previous
model.
looks right deraadt@, and discussed with claudio


# 1.112 21-May-2004 claudio

RFC 2796 bgp route reflector support. This is very useful in conjunction
with templates. looks good, go for it henning@


# 1.111 17-May-2004 djm

extend filter language to allow basic setting of COMMUNITIES attribute.
ok claudio@


# 1.110 08-May-2004 henning

off by one in key too long detection


# 1.109 08-May-2004 henning

fix redefinition detection with manual keyes ipsec


# 1.108 08-May-2004 henning

with manual keyed ipsec, we need keys and spis for both directions -
enforce that


# 1.107 08-May-2004 henning

KNF


# 1.106 08-May-2004 henning

break out the consistency checking for neighbors in its own function,
and verify that peers with ipsec have local-address specified (needed to
set up the flows...)


# 1.105 08-May-2004 henning

allow for neighbor statements without { parameters } block; everything
can be inherited from the group


# 1.104 08-May-2004 henning

add support for ipsec ah with manual keys, pfkey part already does so, and
flesh parser out a bit. also add support for printing ipsec ah with manual
keys in printconf


# 1.103 08-May-2004 henning

factor out the string -> key conversion code used for md5sig and twice for ipsec


# 1.102 07-May-2004 djm

add a filter option to dump prefixes learned in UPDATEs into a PF table,
intended for building realtime BGP blacklists (e.g. with spamd);
ok claudio & henning


# 1.101 06-May-2004 henning

we need a seperate field for the md5 key len, can't use strlen, noticed
by markus some time ago


# 1.100 04-May-2004 claudio

Correctly plug the memory leak and fix a error message.


# 1.99 30-Apr-2004 deraadt

plug memory leaks; henning ok


# 1.98 30-Apr-2004 deraadt

spelling


# 1.97 29-Apr-2004 deraadt

sock -> fd; ok henning


# 1.96 28-Apr-2004 deraadt

FILE * leak; henning ja ja ja ja


# 1.95 28-Apr-2004 henning

allow ah/esp spec with IKE, markus ok


# 1.94 28-Apr-2004 henning

prevent multiple auth methods to be specified


# 1.93 28-Apr-2004 henning

prefix the auth related defines by AUTH_, we had a name clash, markus ok


# 1.92 27-Apr-2004 markus

set conf.auth.methodod for md5, too


# 1.91 27-Apr-2004 henning

ike before in


# 1.90 27-Apr-2004 henning

rename the ipsec struct to auth, move all tcpmd5 related fields in there, and
add a generic "method" field that expresses what method
(none/md5sig/ipsec manual/ipsec ike) is in use
markus ok


# 1.89 27-Apr-2004 henning

parser parts for ipsec ike, markus ok


# 1.88 27-Apr-2004 deraadt

crud stripping; henning ok


# 1.87 27-Apr-2004 henning

curpeer must be set back to curgroup, not NULL


# 1.86 26-Apr-2004 henning

need more checks on the keys


# 1.85 26-Apr-2004 henning

unbreak


# 1.84 26-Apr-2004 henning

don't forget to set keylen, markus


# 1.83 26-Apr-2004 henning

parser support for setting ipsec keys and such, markus ok


# 1.82 25-Apr-2004 henning

reserve upper half of the (internal) ID space for cloned neighbors, claudio ok


# 1.81 25-Apr-2004 henning

fix check wether local-address and neighbor are of same address family -
we have to delay this because the current context might be a group nd not
a single neighbor, claudio ok


# 1.80 25-Apr-2004 henning

add "neighbor cloning", allowing you to specify a prefix and prefixlength
instead of the neighbor's IP address. WHen a connection comes in matching
that mask we clone the neighbor spec.
IPv6 match code by itojun, rde feeding by claudio, ok claudio


# 1.79 24-Apr-2004 henning

some rather boring windows talk at cansecwest made me hack initial support
for IPv6 transport
parts based on a diff from Brent Graveland
ok itojun@ claudio@


Revision tags: OPENBSD_3_5_BASE
# 1.78 11-Mar-2004 claudio

There is no cnumber token in the parser so don't define a type for it.


# 1.77 11-Mar-2004 henning

yes, the keyword table has to be sorted ;-)


# 1.76 11-Mar-2004 claudio

Add basic support for communities. Currently it is only possible to filter
on communities, e.g match from any community 24640:* set localpref 666
OK henning@


# 1.75 10-Mar-2004 henning

oups


# 1.74 10-Mar-2004 henning

implement framework to announce capabilities in the open messages we send.
this includes handling "unsupported optional parameter" notifications from the
peer and retrying without capability announcement. claudio ok


# 1.73 08-Mar-2004 henning

mem leaks in error pathes, mostly from Patrick Latifi


# 1.72 08-Mar-2004 henning

typo in format strin (ugh!) and few missing free()s, partitially from
Patrick Latifi


# 1.71 06-Mar-2004 henning

plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. fatal("yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.70 05-Mar-2004 henning

plug a couple of memory leaks, Patrick Latifi


# 1.69 02-Mar-2004 henning

KNF


# 1.68 02-Mar-2004 henning

flesh out the address and prefix parsing, include v6 code, but reject v6
upwards, claudio ok


# 1.67 01-Mar-2004 henning

make sure AS doesn't exceed upper bound, issue pointed out by
Brent Graveland <brent@graveland.net>


# 1.66 01-Mar-2004 henning

KNF


# 1.65 01-Mar-2004 claudio

Sync printconfig.c with parse.y. OK henning@


# 1.64 01-Mar-2004 claudio

Make it possible to diable the decision process. This is a feature only useful
for route-collectors. OK henning@


# 1.63 26-Feb-2004 claudio

Implement "enforce neighbor-as yes|no" which is by default on for ebgp
neighbors. While doing that check also that the nexthop is valid (not class D
or E and not in 127/8 range). Kill some TODO and XXX and rename the british
neighbour to neighbor as used everywhere else. OK henning@


# 1.62 26-Feb-2004 claudio

No comma at the end of the keywords array. OK henning@


# 1.61 26-Feb-2004 claudio

Add per netwok definition filter sets. So you can now use
network 10.0.0.0/8 set localpref 100
OK henning@


# 1.60 25-Feb-2004 claudio

Rewrite some parts of the mrt dump handling. It is no longer possible to
dump the filtered updates but therefore it is now possible to dump per
neighbor and also to dump the outgoing messages. OK henning@


# 1.59 25-Feb-2004 henning

kill "updates" keyword and use a ordinary string + strcmp at the one place
where it's needed, claudio ok


# 1.58 24-Feb-2004 claudio

Enhance filters. prefixlen knows now 8-24 and 8><24. It is possible to use
prefix 10.0.0.0/8 prefixlen >= 8 and set localpref 100 can be set on a per
neighbor basis. OK henning@


# 1.57 19-Feb-2004 claudio

Make the code more portable. Add some missing header files and make the use
of the queue(3) makros more portable. OK henning@ some time ago.


# 1.56 10-Feb-2004 henning

enforce config file secrecy (correct owner, no rights for group/world)
help and ok theo


# 1.55 09-Feb-2004 henning

make max_prefix an u_int32_t instead of an u_long and change its
meaning as in 0 means no limit insytead of setting it to ULONG_MAX for
no limit


# 1.54 09-Feb-2004 henning

move printing the config to where it belongs


# 1.53 08-Feb-2004 henning

factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too


# 1.52 06-Feb-2004 henning

use a struct bgpd_addr for the address token instead of a in_addr, claudio ok


# 1.51 06-Feb-2004 henning

initial cut at the filtering language.
structs etc to describe a rule, filter rule list management
parser groks filter defs now.

claudio ok, discussion & help also jakob theo


# 1.50 05-Feb-2004 henning

allocate curpeer little earlier.
there's a rather obscure error path where teh later allocation causes
trouble, claudio ok


# 1.49 05-Feb-2004 henning

error message tuning
more power!


# 1.48 05-Feb-2004 henning

introduce group IDs. will be needed for filtering (or rather, ease things
there)
just assign them from the neighbor ID pool - fortunately, that is rather
simple, we just have to make sure that all members of the group and (later)
all filter rules pointing to the group agree on the ID, but it does not need
to stay the same across config reloads.

ok claudio@


# 1.47 03-Feb-2004 henning

replace the previous hack for the internal peer id allocator (which just used
the peer's ip address as u_int32_t) by a real id allocator that tries to
keep locality high. claudio ok


# 1.46 03-Feb-2004 henning

defer free()ing the previous peer list until after parsing the config file
so in the parser we can access it. will be needed soon.


# 1.45 01-Feb-2004 claudio

Set sane default announce types according to the peer type. For IBGP use
announce all and for EBGP use announce self. OK henning@


# 1.44 28-Jan-2004 henning

properly whine when password is too long instead of silently truncating


# 1.43 28-Jan-2004 henning

implement
tcp md5sig password
so that the key can be given in ascii, what unfortunately limits the key space
(cisco/juniper compat...)
we keep the ability to specify the key in hex whithout these limits.

help & ok markus


# 1.42 27-Jan-2004 henning

use a struct bgpd_addr instead of sockaddr_in for peer_config->local_addr and
->remote_addr for easier multiprotocol support

ok claudio@


# 1.41 26-Jan-2004 henning

rename "tcp signature" to "tcp md5sig" - the name is misleading, wether
ietf wants to call it so or not
prodded by theo


# 1.40 26-Jan-2004 henning

first cut at tcpmd5 setup seupport from within bgpd. works so far.
with help from hshoexer@ and markus@
ok claudio@ hshoexer@ markus@


# 1.39 24-Jan-2004 henning

eek, no, ERROR is of course not unused


# 1.38 24-Jan-2004 mcbride

Remove unused terminals.

ok henning@


# 1.37 22-Jan-2004 henning

provide a log_debug and use it in rde.c.
with this, logit() can be a private function.
we don't need to include syslog.h in bgpd.h any more; log.c and parse.y
who need it include it directly now.


# 1.36 17-Jan-2004 claudio

Make it possible to announce own networks. In the RDE these prefixes are
attached to a pseudo peer and inserted like all other prefixes into the RIB.
OK henning@


# 1.35 17-Jan-2004 henning

KNF


# 1.34 13-Jan-2004 claudio

Implement a max-prefix and a announce none | self | all neighbor statement.
The first limits the number of sent prefixes per peer the latter controls
which prefix we do annouce to the neighbor.
Another looks good from henning@


# 1.33 06-Jan-2004 henning

small bug that was not so easy to fix: we did not allow empty lines (or
comment-only lines) in the middle of neighbor/group blocks. as first or
last line in thise blocks they were accepted, but not in between.

ok deraadt@


# 1.32 06-Jan-2004 henning

allow holdtime and holdtime min to be configuered per peer

ok claudio@


# 1.31 06-Jan-2004 henning

2004


# 1.30 05-Jan-2004 claudio

Big overhaul of the mrt code.
Dumping of incomming bgp messages is now possible and dumping the (not yet)
filtered updates works too. Per neighbor dumps are still missing.
OK henning@


# 1.29 05-Jan-2004 henning

missing fclose()

fd leak pointed out by Patrick Latifi, but it was not so easy to fix before
I just killed the support for config from stdin and his fix didn't work.
however, this is the 16 bytes memory leak on config reload i was hunting for
some time, big thanks to Patrick!


# 1.28 05-Jan-2004 henning

remove support for reading configuration from stdin.
that really does not make sense with a daemon and probably breaks horribly
on config reload


# 1.27 05-Jan-2004 henning

fix off by ones with strlcpy()
memleak fixes in error paths
From: Patrick Latifi <pat@eyeo.org>


# 1.26 03-Jan-2004 henning

move some session specific stuff to session.h and make the few files
that need it include that


# 1.25 03-Jan-2004 henning

decouple the peer list from bgpd_config.
so many parts of bgpd are not at all interested in the session specific peer
structs... allows for some further cleaning


# 1.24 27-Dec-2003 henning

bgpid -> router-id
local-addr -> local-address


# 1.23 27-Dec-2003 henning

fix thinko


# 1.22 27-Dec-2003 henning

"no fib-update" -> "fib-update [yes|no]"
makes more sense this way


# 1.21 27-Dec-2003 henning

few fatal()s should really be fatalx()
From: Dries Schellekens <gwyllion@ace.ulyssis.org>


# 1.20 26-Dec-2003 jakob

add option 'log updates' to log updates. ok henning@


# 1.19 26-Dec-2003 henning

when this project started and i added the fatal() function, I made it take
the error number as parameter instead of accessing errno, because in one
place the error number was not in errno but fetched from a socket.
now, of course it makes much more sense to just set errno to the error number
just fecthed in this one place instead of having hundreds of fatal() calls
all transfer the errno round and round and round...
fix this, and also provide a fatalx, which does not care for errno and doesn't
invoke strerror.
oh, btw, in the place where we fetch the err # from the socket, we don't
call fatal anymore anyway...


# 1.18 25-Dec-2003 henning

style


# 1.17 25-Dec-2003 henning

must not remove macros vis cmdline after parsinf is done, we will need them
again on reload


# 1.16 25-Dec-2003 henning

don't leak in yyerror()


# 1.15 25-Dec-2003 henning

o can't TAILQ_FOREACH when we TAILQ_REMOVE in the loop
o free(sym)


# 1.14 25-Dec-2003 henning

free where it was allocated; much easier to verify


# 1.13 25-Dec-2003 henning

implement "passive": do not attempt to open a tcp connection to the
neighbor system


# 1.12 24-Dec-2003 henning

local-addr, not local-address.
it's better when documentation and code agree on the keyword...


# 1.11 24-Dec-2003 henning

add option to not touch the kernel routing table


# 1.10 23-Dec-2003 henning

better syntax for minimum accepted holdtime


# 1.9 23-Dec-2003 henning

allow the listening address to be specified, default to INADDR_ANY
should make jose@ happy


# 1.8 22-Dec-2003 deraadt

spacing


# 1.7 22-Dec-2003 deraadt

fix indent


# 1.6 22-Dec-2003 henning

ease grammar a lot. eleminate pstate and let yacc do the work for us instead.
nearly completely from theo with minor adjustment by me.


# 1.5 21-Dec-2003 henning

overhaul the write buffering code.
introduce msgbuf API and bundle all info needed for the write buffers in a
struct msgbuf.
also switch to a write queue per handled connection (each bgp session, each
pipe) instead of one big one.
fixes some subtle problems and is overall nicer.

ok claudio@


# 1.4 20-Dec-2003 henning

few missing break; in default: cases in switch; one noticed by tedu@


# 1.3 19-Dec-2003 henning

fix copyright


# 1.2 17-Dec-2003 henning

style


# 1.1 17-Dec-2003 henning

welcome, bgpd
started by me some time ago with moral support from theo, the proceeded up to
the point where the session engine worked correctly. claudio jeker joined
then and did a lot of work in the RDE.
it is not particulary usefull as application right now as parts are still
missing but is imported to enable more people to work on it.
status:
BGP sessions get established fine, OPEN messages and then KEEPALIVEs
exchanged etc. session FSM works fine; NOTIFICATIONs are handled fine, and
all connection drops etc I provoked get handled fine.
Incoming UPDATE messgages are parsed well and the data entered to the RIB,
the decision process is not yet there, neither is outgoing UPDATEs or sync
to the kernel routing table.

not connected to the builds yet.