summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd/rde_filter.c
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2004-08-06 12:04:09 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2004-08-06 12:04:09 +0000
commit1702f711eb5a6da7d226fd633c14c8a22cc5c448 (patch)
treef5642b4adf97d5d2f86ff168b7bbb9855f6a18b1 /usr.sbin/bgpd/rde_filter.c
parent232c877040ea69df2d195a2de71e66da045030f0 (diff)
Monster diff to get one step closer to IPv6 support.
Cleanup path attribute handling. First of all kill struct attr_flags, all those infos are now in struct rde_aspath. Second move attribute parser functions into rde.c, rde_attr.c is shared between bgpd and bgpctl. Third reimplementation of the nexthop handling. Make it IPv6 ready and fix some major bug relating to "set nexthop". henning@ OK if it breaks nothing
Diffstat (limited to 'usr.sbin/bgpd/rde_filter.c')
-rw-r--r--usr.sbin/bgpd/rde_filter.c60
1 files changed, 31 insertions, 29 deletions
diff --git a/usr.sbin/bgpd/rde_filter.c b/usr.sbin/bgpd/rde_filter.c
index 22d880364c5..785176d0788 100644
--- a/usr.sbin/bgpd/rde_filter.c
+++ b/usr.sbin/bgpd/rde_filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_filter.c,v 1.15 2004/08/05 18:44:19 claudio Exp $ */
+/* $OpenBSD: rde_filter.c,v 1.16 2004/08/06 12:04:08 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -25,11 +25,11 @@
extern struct filter_head *rules_l; /* XXX ugly */
-int rde_filter_match(struct filter_rule *, struct attr_flags *,
+int rde_filter_match(struct filter_rule *, struct rde_aspath *,
struct bgpd_addr *, u_int8_t);
enum filter_actions
-rde_filter(struct rde_peer *peer, struct attr_flags *attrs,
+rde_filter(struct rde_peer *peer, struct rde_aspath *asp,
struct bgpd_addr *prefix, u_int8_t prefixlen, enum directions dir)
{
struct filter_rule *f;
@@ -44,8 +44,8 @@ rde_filter(struct rde_peer *peer, struct attr_flags *attrs,
if (f->peer.peerid != 0 &&
f->peer.peerid != peer->conf.id)
continue;
- if (rde_filter_match(f, attrs, prefix, prefixlen)) {
- rde_apply_set(attrs, &f->set);
+ if (rde_filter_match(f, asp, prefix, prefixlen)) {
+ rde_apply_set(asp, &f->set);
if (f->action != ACTION_NONE)
action = f->action;
if (f->quick)
@@ -56,39 +56,41 @@ rde_filter(struct rde_peer *peer, struct attr_flags *attrs,
}
void
-rde_apply_set(struct attr_flags *attrs, struct filter_set *set)
+rde_apply_set(struct rde_aspath *asp, struct filter_set *set)
{
+ struct bgpd_addr addr;
struct aspath *new;
u_int16_t as;
- if (attrs == NULL)
+ if (asp == NULL)
return;
if (set->flags & SET_LOCALPREF)
- attrs->lpref = set->localpref;
+ asp->lpref = set->localpref;
if (set->flags & SET_MED)
- attrs->med = set->med;
- if (set->flags & SET_NEXTHOP)
- attrs->nexthop = set->nexthop;
- if (set->flags & SET_NEXTHOP_REJECT)
- attrs->nexthop_reject = 1;
- if (set->flags & SET_NEXTHOP_BLACKHOLE)
- attrs->nexthop_blackhole = 1;
+ asp->med = set->med;
+
+ /* XXX and uglier */
+ bzero(&addr, sizeof(addr));
+ addr.af = AF_INET;
+ addr.v4.s_addr = set->nexthop.s_addr;
+ nexthop_modify(asp, &addr, set->flags);
+
if (set->flags & SET_PREPEND) {
as = rde_local_as();
- new = aspath_prepend(attrs->aspath, as, set->prepend);
- aspath_put(attrs->aspath);
- attrs->aspath = new;
+ new = aspath_prepend(asp->aspath, as, set->prepend);
+ aspath_put(asp->aspath);
+ asp->aspath = new;
}
if (set->flags & SET_PFTABLE)
- strlcpy(attrs->pftable, set->pftable, sizeof(attrs->pftable));
+ strlcpy(asp->pftable, set->pftable, sizeof(asp->pftable));
if (set->flags & SET_COMMUNITY) {
struct attr *a;
- if ((a = attr_optget(attrs, ATTR_COMMUNITIES)) == NULL) {
- attr_optadd(attrs, ATTR_OPTIONAL|ATTR_TRANSITIVE,
+ if ((a = attr_optget(asp, ATTR_COMMUNITIES)) == NULL) {
+ attr_optadd(asp, ATTR_OPTIONAL|ATTR_TRANSITIVE,
ATTR_COMMUNITIES, NULL, 0);
- if ((a = attr_optget(attrs, ATTR_COMMUNITIES)) == NULL)
+ if ((a = attr_optget(asp, ATTR_COMMUNITIES)) == NULL)
fatalx("internal community bug");
}
community_set(a, set->community.as, set->community.type);
@@ -96,17 +98,17 @@ rde_apply_set(struct attr_flags *attrs, struct filter_set *set)
}
int
-rde_filter_match(struct filter_rule *f, struct attr_flags *attrs,
+rde_filter_match(struct filter_rule *f, struct rde_aspath *asp,
struct bgpd_addr *prefix, u_int8_t plen)
{
- if (attrs != NULL && f->match.as.type != AS_NONE)
- if (aspath_match(attrs->aspath, f->match.as.type,
+ if (asp != NULL && f->match.as.type != AS_NONE)
+ if (aspath_match(asp->aspath, f->match.as.type,
f->match.as.as) == 0)
return (0);
- if (attrs != NULL && f->match.community.as != 0)
- if (rde_filter_community(attrs, f->match.community.as,
+ if (asp != NULL && f->match.community.as != 0)
+ if (rde_filter_community(asp, f->match.community.as,
f->match.community.type) == 0)
return (0);
@@ -178,11 +180,11 @@ rde_filter_match(struct filter_rule *f, struct attr_flags *attrs,
}
int
-rde_filter_community(struct attr_flags *attr, int as, int type)
+rde_filter_community(struct rde_aspath *asp, int as, int type)
{
struct attr *a;
- a = attr_optget(attr, ATTR_COMMUNITIES);
+ a = attr_optget(asp, ATTR_COMMUNITIES);
if (a == NULL)
/* no communities, no match */
return (0);