diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-07-01 09:19:25 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-07-01 09:19:25 +0000 |
commit | e0755c67259be27e90bb1c2c5d78acf0d8ac415c (patch) | |
tree | d08ff36155faaae8d1e6bf87c7766ca38e93980e | |
parent | ae36f7fa11ba3a91c7f8fb688683282a5042d5b7 (diff) |
Make the pftable filter set use the name2id "cache" like the route labels.
This saves 14 bytes per aspath. OK henning@
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 8 | ||||
-rw-r--r-- | usr.sbin/bgpd/name2id.c | 28 | ||||
-rw-r--r-- | usr.sbin/bgpd/pftable.c | 6 | ||||
-rw-r--r-- | usr.sbin/bgpd/printconf.c | 5 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.c | 8 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.h | 6 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_filter.c | 14 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_rib.c | 16 |
8 files changed, 66 insertions, 25 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 2c888f73ba3..b55b424c0b9 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.172 2005/06/29 09:43:25 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.173 2005/07/01 09:19:24 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -579,6 +579,7 @@ enum action_types { ACTION_SET_COMMUNITY, /* ACTION_SCRUB_COMMUNITY, */ ACTION_PFTABLE, + ACTION_PFTABLE_ID, ACTION_RTLABEL, ACTION_RTLABEL_ID }; @@ -707,6 +708,11 @@ u_int16_t rtlabel_name2id(char *); const char *rtlabel_id2name(u_int16_t); void rtlabel_unref(u_int16_t); void rtlabel_ref(u_int16_t); +u_int16_t pftable_name2id(char *); +const char *pftable_id2name(u_int16_t); +void pftable_unref(u_int16_t); +void pftable_ref(u_int16_t); + /* rde_filter.c */ void filterset_free(struct filter_set_head *); diff --git a/usr.sbin/bgpd/name2id.c b/usr.sbin/bgpd/name2id.c index 1ee5f50a8f0..8b217a49db2 100644 --- a/usr.sbin/bgpd/name2id.c +++ b/usr.sbin/bgpd/name2id.c @@ -1,4 +1,4 @@ -/* $OpenBSD: name2id.c,v 1.3 2005/06/29 09:43:25 claudio Exp $ */ +/* $OpenBSD: name2id.c,v 1.4 2005/07/01 09:19:24 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Henning Brauer <henning@openbsd.org> @@ -45,7 +45,7 @@ void _ref(struct n2id_labels *, u_int16_t); int _exists(struct n2id_labels *, const char *); struct n2id_labels rt_labels = TAILQ_HEAD_INITIALIZER(rt_labels); -struct n2id_labels filter_labels = TAILQ_HEAD_INITIALIZER(filter_labels); +struct n2id_labels pftable_labels = TAILQ_HEAD_INITIALIZER(pftable_labels); u_int16_t rtlabel_name2id(char *name) @@ -72,6 +72,30 @@ rtlabel_ref(u_int16_t id) } u_int16_t +pftable_name2id(char *name) +{ + return (_name2id(&rt_labels, name)); +} + +const char * +pftable_id2name(u_int16_t id) +{ + return (_id2name(&rt_labels, id)); +} + +void +pftable_unref(u_int16_t id) +{ + _unref(&rt_labels, id); +} + +void +pftable_ref(u_int16_t id) +{ + _ref(&rt_labels, id); +} + +u_int16_t _name2id(struct n2id_labels *head, const char *name) { struct n2id_label *label, *p = NULL; diff --git a/usr.sbin/bgpd/pftable.c b/usr.sbin/bgpd/pftable.c index 95c9739ceae..13b8c48d252 100644 --- a/usr.sbin/bgpd/pftable.c +++ b/usr.sbin/bgpd/pftable.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pftable.c,v 1.4 2004/11/02 17:00:52 henning Exp $ */ +/* $OpenBSD: pftable.c,v 1.5 2005/07/01 09:19:24 claudio Exp $ */ /* * Copyright (c) 2004 Damien Miller <djm@openbsd.org> @@ -76,7 +76,7 @@ pftable_change(struct pf_table *pft) if (ret == -1) { if (errno == EINVAL) return (0); - log_warn("pftable_change ioctl %s", strerror(errno)); + log_warn("pftable_change ioctl"); } return (ret); @@ -95,7 +95,7 @@ pftable_clear(const char *name) sizeof(tio.pfrio_table.pfrt_name)); if (ioctl(devpf, DIOCRCLRADDRS, &tio) != 0) { - log_warn("pftable_clear ioctl %s", strerror(errno)); + log_warn("pftable_clear ioctl"); return (-1); } diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c index 564082e4961..3b333b77718 100644 --- a/usr.sbin/bgpd/printconf.c +++ b/usr.sbin/bgpd/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.43 2005/06/29 09:43:25 claudio Exp $ */ +/* $OpenBSD: printconf.c,v 1.44 2005/07/01 09:19:24 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -130,8 +130,9 @@ print_set(struct filter_set_head *set) printf("rtlabel %s ", s->action.rtlabel); break; case ACTION_RTLABEL_ID: + case ACTION_PFTABLE_ID: /* not possible */ - printf("rtlabel id %d ", s->action.id); + printf("king bula saiz: config broken"); break; } } diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 25716d6189d..a8684266ae1 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.163 2005/06/29 09:43:25 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.164 2005/07/01 09:19:24 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -1660,16 +1660,16 @@ rde_send_kroute(struct prefix *new, struct prefix *old) * pf table specific functions */ void -rde_send_pftable(const char *table, struct bgpd_addr *addr, +rde_send_pftable(u_int16_t id, struct bgpd_addr *addr, u_int8_t len, int del) { struct pftable_msg pfm; - if (*table == '\0') + if (id == 0) return; bzero(&pfm, sizeof(pfm)); - strlcpy(pfm.pftable, table, sizeof(pfm.pftable)); + strlcpy(pfm.pftable, pftable_id2name(id), sizeof(pfm.pftable)); memcpy(&pfm.addr, addr, sizeof(pfm.addr)); pfm.len = len; diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index a978171e899..8072c87c8bf 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.66 2005/06/29 09:43:26 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.67 2005/07/01 09:19:24 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and @@ -158,11 +158,11 @@ struct rde_aspath { struct rde_peer *peer; struct aspath *aspath; struct nexthop *nexthop; /* may be NULL */ - char pftable[PFTABLE_LEN]; u_int32_t med; /* multi exit disc */ u_int32_t lpref; /* local pref */ u_int32_t weight; /* low prio lpref */ u_int16_t rtlabelid; /* route label id */ + u_int16_t pftableid; /* pf table id */ u_int16_t flags; /* internally used */ u_int16_t prefix_cnt; /* # of prefixes */ u_int16_t active_cnt; /* # of active prefixes */ @@ -238,7 +238,7 @@ struct prefix { /* rde.c */ void rde_send_kroute(struct prefix *, struct prefix *); void rde_send_nexthop(struct bgpd_addr *, int); -void rde_send_pftable(const char *, struct bgpd_addr *, +void rde_send_pftable(u_int16_t, struct bgpd_addr *, u_int8_t, int); void rde_send_pftable_commit(void); diff --git a/usr.sbin/bgpd/rde_filter.c b/usr.sbin/bgpd/rde_filter.c index 1a6f2c5df72..98104dbc663 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.28 2005/06/29 09:43:26 claudio Exp $ */ +/* $OpenBSD: rde_filter.c,v 1.29 2005/07/01 09:19:24 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> @@ -188,8 +188,14 @@ rde_apply_set(struct rde_aspath *asp, struct filter_set_head *sh, set->action.community.type); break; case ACTION_PFTABLE: - strlcpy(asp->pftable, set->action.pftable, - sizeof(asp->pftable)); + /* convert pftable name to an id */ + set->action.id = pftable_name2id(set->action.pftable); + set->type = ACTION_PFTABLE_ID; + /* FALLTHROUGH */ + case ACTION_PFTABLE_ID: + pftable_unref(asp->pftableid); + asp->pftableid = set->action.id; + pftable_ref(asp->pftableid); break; case ACTION_RTLABEL: /* convert the route label to an id for faster access */ @@ -309,6 +315,8 @@ filterset_free(struct filter_set_head *sh) SIMPLEQ_REMOVE_HEAD(sh, entry); if (s->type == ACTION_RTLABEL_ID) rtlabel_unref(s->action.id); + else if (s->type == ACTION_PFTABLE_ID) + pftable_unref(s->action.id); free(s); } diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 61b36d56792..5cbe6825088 100644 --- a/usr.sbin/bgpd/rde_rib.c +++ b/usr.sbin/bgpd/rde_rib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_rib.c,v 1.67 2005/06/29 09:43:26 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.68 2005/07/01 09:19:24 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -81,7 +81,7 @@ path_update(struct rde_peer *peer, struct rde_aspath *nasp, struct rde_aspath *asp; struct prefix *p; - rde_send_pftable(nasp->pftable, prefix, prefixlen, 0); + rde_send_pftable(nasp->pftableid, prefix, prefixlen, 0); rde_send_pftable_commit(); if ((p = prefix_get(peer, prefix, prefixlen)) != NULL) { @@ -136,10 +136,12 @@ path_compare(struct rde_aspath *a, struct rde_aspath *b) return (1); if (a->rtlabelid < b->rtlabelid) return (-1); + if (a->pftableid > b->pftableid) + return (1); + if (a->pftableid < b->pftableid) + return (-1); - r = strcmp(a->pftable, b->pftable); - if (r == 0) - r = aspath_compare(a->aspath, b->aspath); + r = aspath_compare(a->aspath, b->aspath); if (r == 0) r = nexthop_compare(a->nexthop, b->nexthop); if (r > 0) @@ -196,7 +198,7 @@ path_remove(struct rde_aspath *asp) while ((p = LIST_FIRST(&asp->prefix_h)) != NULL) { /* Commit is done in peer_down() */ pt_getaddr(p->prefix, &addr); - rde_send_pftable(p->aspath->pftable, + rde_send_pftable(p->aspath->pftableid, &addr, p->prefix->prefixlen, 1); prefix_destroy(p); @@ -492,7 +494,7 @@ prefix_remove(struct rde_peer *peer, struct bgpd_addr *prefix, int prefixlen) asp = p->aspath; - rde_send_pftable(asp->pftable, prefix, prefixlen, 1); + rde_send_pftable(asp->pftableid, prefix, prefixlen, 1); rde_send_pftable_commit(); prefix_unlink(p); |