diff options
author | Renato Westphal <renato@cvs.openbsd.org> | 2016-02-21 19:01:13 +0000 |
---|---|---|
committer | Renato Westphal <renato@cvs.openbsd.org> | 2016-02-21 19:01:13 +0000 |
commit | 6517d448a8973e42c3d1905856b10283ef873c91 (patch) | |
tree | e3b8bea6aee1e0e47efd0fc7722b0c1c20023352 /usr.sbin | |
parent | 7f20d807da81b64747d4d2e6b69f197eb362c385 (diff) |
Move some functions around and rename a few variables and functions.
The sooner we do these changes the better. This rearrangement will make
the code easier to read.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/eigrpd/eigrpe.c | 6 | ||||
-rw-r--r-- | usr.sbin/eigrpd/eigrpe.h | 8 | ||||
-rw-r--r-- | usr.sbin/eigrpd/interface.c | 96 | ||||
-rw-r--r-- | usr.sbin/eigrpd/kroute.c | 9 | ||||
-rw-r--r-- | usr.sbin/eigrpd/parse.y | 268 | ||||
-rw-r--r-- | usr.sbin/eigrpd/rde_dual.c | 4 |
6 files changed, 195 insertions, 196 deletions
diff --git a/usr.sbin/eigrpd/eigrpe.c b/usr.sbin/eigrpd/eigrpe.c index 87379beb9c5..a6941fb1c32 100644 --- a/usr.sbin/eigrpd/eigrpe.c +++ b/usr.sbin/eigrpd/eigrpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrpe.c,v 1.14 2016/02/21 18:56:49 renato Exp $ */ +/* $OpenBSD: eigrpe.c,v 1.15 2016/02/21 19:01:12 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -470,7 +470,7 @@ eigrpe_dispatch_rde(int fd, short event, void *bula) fatalx("invalid size of rinfo"); memcpy(&rinfo, imsg.data, sizeof(rinfo)); - ei = eigrp_iface_find_id(imsg.hdr.peerid); + ei = eigrp_if_lookup_id(imsg.hdr.peerid); if (ei == NULL) { log_debug("%s: cannot find interface", __func__); @@ -518,7 +518,7 @@ eigrpe_dispatch_rde(int fd, short event, void *bula) break; case IMSG_SEND_MUPDATE_END: case IMSG_SEND_MQUERY_END: - ei = eigrp_iface_find_id(imsg.hdr.peerid); + ei = eigrp_if_lookup_id(imsg.hdr.peerid); if (ei == NULL) { log_debug("%s: cannot find interface", __func__); diff --git a/usr.sbin/eigrpd/eigrpe.h b/usr.sbin/eigrpd/eigrpe.h index 1f13669d3a4..c3921067260 100644 --- a/usr.sbin/eigrpd/eigrpe.h +++ b/usr.sbin/eigrpd/eigrpe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrpe.h,v 1.8 2016/02/21 18:40:56 renato Exp $ */ +/* $OpenBSD: eigrpe.h,v 1.9 2016/02/21 19:01:12 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -90,8 +90,8 @@ void eigrpe_stats_ctl(struct ctl_conn *); /* interface.c */ struct iface *if_new(struct eigrpd_conf *, struct kif *); void if_del(struct iface *); -void if_init(struct eigrpd_conf *, struct iface *); struct iface *if_lookup(struct eigrpd_conf *, unsigned int); +void if_init(struct eigrpd_conf *, struct iface *); void if_addr_new(struct iface *, struct kaddr *); void if_addr_del(struct iface *, struct kaddr *); struct if_addr *if_addr_lookup(struct if_addr_head *, struct kaddr *); @@ -101,10 +101,10 @@ void if_update(struct iface *, int); struct eigrp_iface *eigrp_if_new(struct eigrpd_conf *, struct eigrp *, struct kif *); void eigrp_if_del(struct eigrp_iface *); +struct eigrp_iface *eigrp_if_lookup(struct iface *, int, uint16_t); +struct eigrp_iface *eigrp_if_lookup_id(uint32_t); void eigrp_if_start(struct eigrp_iface *); void eigrp_if_reset(struct eigrp_iface *); -struct eigrp_iface *eigrp_if_lookup(struct iface *, int, uint16_t); -struct eigrp_iface *eigrp_iface_find_id(uint32_t); struct ctl_iface *if_to_ctl(struct eigrp_iface *); void if_set_sockbuf(int); int if_join_ipv4_group(struct iface *, struct in_addr *); diff --git a/usr.sbin/eigrpd/interface.c b/usr.sbin/eigrpd/interface.c index b377d29fcf2..7883c2133fe 100644 --- a/usr.sbin/eigrpd/interface.c +++ b/usr.sbin/eigrpd/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.14 2016/02/21 18:56:49 renato Exp $ */ +/* $OpenBSD: interface.c,v 1.15 2016/02/21 19:01:12 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -105,6 +105,18 @@ if_del(struct iface *iface) free(iface); } +struct iface * +if_lookup(struct eigrpd_conf *xconf, unsigned int ifindex) +{ + struct iface *iface; + + TAILQ_FOREACH(iface, &xconf->iface_list, entry) + if (iface->ifindex == ifindex) + return (iface); + + return (NULL); +} + void if_init(struct eigrpd_conf *xconf, struct iface *iface) { @@ -125,34 +137,22 @@ if_init(struct eigrpd_conf *xconf, struct iface *iface) fatalx("interface rdomain mismatch"); } -struct iface * -if_lookup(struct eigrpd_conf *xconf, unsigned int ifindex) -{ - struct iface *iface; - - TAILQ_FOREACH(iface, &xconf->iface_list, entry) - if (iface->ifindex == ifindex) - return (iface); - - return (NULL); -} - void -if_addr_new(struct iface *iface, struct kaddr *kaddr) +if_addr_new(struct iface *iface, struct kaddr *ka) { struct if_addr *if_addr; struct eigrp_iface *ei; - if (if_addr_lookup(&iface->addr_list, kaddr) != NULL) + if (if_addr_lookup(&iface->addr_list, ka) != NULL) return; if ((if_addr = calloc(1, sizeof(*if_addr))) == NULL) fatal("if_addr_new: calloc"); - if_addr->af = kaddr->af; - if_addr->addr = kaddr->addr; - if_addr->prefixlen = kaddr->prefixlen; - if_addr->dstbrd = kaddr->dstbrd; + if_addr->af = ka->af; + if_addr->addr = ka->addr; + if_addr->prefixlen = ka->prefixlen; + if_addr->dstbrd = ka->dstbrd; TAILQ_INSERT_TAIL(&iface->addr_list, if_addr, entry); @@ -164,12 +164,12 @@ if_addr_new(struct iface *iface, struct kaddr *kaddr) } void -if_addr_del(struct iface *iface, struct kaddr *kaddr) +if_addr_del(struct iface *iface, struct kaddr *ka) { struct if_addr *if_addr; struct eigrp_iface *ei; - if_addr = if_addr_lookup(&iface->addr_list, kaddr); + if_addr = if_addr_lookup(&iface->addr_list, ka); if (if_addr == NULL) return; @@ -183,15 +183,15 @@ if_addr_del(struct iface *iface, struct kaddr *kaddr) } struct if_addr * -if_addr_lookup(struct if_addr_head *addr_list, struct kaddr *kaddr) +if_addr_lookup(struct if_addr_head *addr_list, struct kaddr *ka) { struct if_addr *if_addr; - int af = kaddr->af; + int af = ka->af; TAILQ_FOREACH(if_addr, addr_list, entry) - if (!eigrp_addrcmp(af, &if_addr->addr, &kaddr->addr) && - if_addr->prefixlen == kaddr->prefixlen && - !eigrp_addrcmp(af, &if_addr->dstbrd, &kaddr->dstbrd)) + if (!eigrp_addrcmp(af, &if_addr->addr, &ka->addr) && + if_addr->prefixlen == ka->prefixlen && + !eigrp_addrcmp(af, &if_addr->dstbrd, &ka->dstbrd)) return (if_addr); return (NULL); @@ -292,7 +292,7 @@ eigrp_if_new(struct eigrpd_conf *xconf, struct eigrp *eigrp, struct kif *kif) ei->state = IF_STA_DOWN; /* get next unused ifaceid */ - while (eigrp_iface_find_id(ifacecnt++)) + while (eigrp_if_lookup_id(ifacecnt++)) ; ei->ifaceid = ifacecnt; ei->eigrp = eigrp; @@ -339,6 +339,27 @@ eigrp_if_del(struct eigrp_iface *ei) free(ei); } +struct eigrp_iface * +eigrp_if_lookup(struct iface *iface, int af, uint16_t as) +{ + struct eigrp_iface *ei; + + TAILQ_FOREACH(ei, &iface->ei_list, i_entry) + if (ei->eigrp->af == af && + ei->eigrp->as == as) + return (ei); + + return (NULL); +} + +struct eigrp_iface * +eigrp_if_lookup_id(uint32_t ifaceid) +{ + struct eigrp_iface e; + e.ifaceid = ifaceid; + return (RB_FIND(iface_id_head, &ifaces_by_id, &e)); +} + void eigrp_if_start(struct eigrp_iface *ei) { @@ -419,27 +440,6 @@ eigrp_if_reset(struct eigrp_iface *ei) eigrp_if_stop_hello_timer(ei); } -struct eigrp_iface * -eigrp_iface_find_id(uint32_t ifaceid) -{ - struct eigrp_iface e; - e.ifaceid = ifaceid; - return (RB_FIND(iface_id_head, &ifaces_by_id, &e)); -} - -struct eigrp_iface * -eigrp_if_lookup(struct iface *iface, int af, uint16_t as) -{ - struct eigrp_iface *ei; - - TAILQ_FOREACH(ei, &iface->ei_list, i_entry) - if (ei->eigrp->af == af && - ei->eigrp->as == as) - return (ei); - - return (NULL); -} - /* timers */ /* ARGSUSED */ void diff --git a/usr.sbin/eigrpd/kroute.c b/usr.sbin/eigrpd/kroute.c index 13a40aec268..d2466c88d03 100644 --- a/usr.sbin/eigrpd/kroute.c +++ b/usr.sbin/eigrpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.12 2016/02/21 18:56:49 renato Exp $ */ +/* $OpenBSD: kroute.c,v 1.13 2016/02/21 19:01:12 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -199,7 +199,7 @@ kif_redistribute(void) sizeof(struct kif)); TAILQ_FOREACH(ka, &kif->addrs, entry) { main_imsg_compose_eigrpe(IMSG_NEWADDR, 0, &ka->a, - sizeof(struct kaddr)); + sizeof(ka->a)); } } } @@ -935,8 +935,7 @@ if_newaddr(unsigned short ifindex, struct sockaddr *ifa, struct sockaddr *mask, TAILQ_INSERT_TAIL(&kif->addrs, ka, entry); /* notify eigrpe about new address */ - main_imsg_compose_eigrpe(IMSG_NEWADDR, 0, &ka->a, - sizeof(struct kaddr)); + main_imsg_compose_eigrpe(IMSG_NEWADDR, 0, &ka->a, sizeof(ka->a)); } void @@ -1020,7 +1019,7 @@ if_deladdr(unsigned short ifindex, struct sockaddr *ifa, struct sockaddr *mask, /* notify eigrpe about removed address */ main_imsg_compose_eigrpe(IMSG_DELADDR, 0, &ka->a, - sizeof(struct kaddr)); + sizeof(ka->a)); TAILQ_REMOVE(&kif->addrs, ka, entry); free(ka); return; diff --git a/usr.sbin/eigrpd/parse.y b/usr.sbin/eigrpd/parse.y index 37082200daf..0d0df53a43a 100644 --- a/usr.sbin/eigrpd/parse.y +++ b/usr.sbin/eigrpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.8 2016/02/21 18:56:49 renato Exp $ */ +/* $OpenBSD: parse.y,v 1.9 2016/02/21 19:01:12 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -79,7 +79,7 @@ char *symget(const char *); void clear_config(struct eigrpd_conf *xconf); uint32_t get_rtr_id(void); -int host(const char *, union eigrpd_addr *, uint8_t *); +int get_prefix(const char *, union eigrpd_addr *, uint8_t *); static struct eigrpd_conf *conf; static int errors = 0; @@ -149,7 +149,7 @@ grammar : /* empty */ | grammar error '\n' { file->errors++; } ; -include : INCLUDE STRING { +include : INCLUDE STRING { struct file *nfile; if ((nfile = pushfile($2, 1)) == NULL) { @@ -177,6 +177,13 @@ string : string STRING { | STRING ; +optnl : '\n' optnl + | + ; + +nl : '\n' optnl /* one newline or more */ + ; + yesno : YES { $$ = 1; } | NO { $$ = 0; } ; @@ -189,7 +196,7 @@ eigrp_af : IPV4 { $$ = AF_INET; } | IPV6 { $$ = AF_INET6; } ; -varset : STRING '=' string { +varset : STRING '=' string { if (conf->opts & EIGRPD_OPT_VERBOSE) printf("%s = \"%s\"\n", $1, $3); if (symset($1, $3, 0) == -1) @@ -248,6 +255,123 @@ conf_main : ROUTERID STRING { | defaults ; +af : AF eigrp_af { + af = $2; + afdefs = *defs; + defs = &afdefs; + } af_block { + af = AF_UNSPEC; + defs = &globaldefs; + } + ; + +af_block : '{' optnl afopts_l '}' + | '{' optnl '}' + | + ; + +afopts_l : afopts_l afoptsl nl + | afoptsl optnl + ; + +afoptsl : as + | defaults + ; + +as : AS NUMBER { + if ($2 < EIGRP_MIN_AS || $2 > EIGRP_MAX_AS) { + yyerror("invalid autonomous-system"); + YYERROR; + } + eigrp = conf_get_instance($2); + if (eigrp == NULL) + YYERROR; + + asdefs = *defs; + defs = &asdefs; + } as_block { + memcpy(eigrp->kvalues, defs->kvalues, + sizeof(eigrp->kvalues)); + eigrp->active_timeout = defs->active_timeout; + eigrp->maximum_hops = defs->maximum_hops; + eigrp->maximum_paths = defs->maximum_paths; + eigrp->variance = defs->variance; + eigrp->dflt_metric = defs->dflt_metric; + eigrp = NULL; + defs = &afdefs; + } + ; + +as_block : '{' optnl asopts_l '}' + | '{' optnl '}' + | + ; + +asopts_l : asopts_l asoptsl nl + | asoptsl optnl + ; + +asoptsl : interface + | redistribute { + SIMPLEQ_INSERT_TAIL(&eigrp->redist_list, $1, entry); + } + | defaults + ; + +interface : INTERFACE STRING { + struct kif *kif; + + if ((kif = kif_findname($2)) == NULL) { + yyerror("unknown interface %s", $2); + free($2); + YYERROR; + } + free($2); + ei = conf_get_if(kif); + if (ei == NULL) + YYERROR; + + ifacedefs = *defs; + defs = &ifacedefs; + } interface_block { + ei->hello_holdtime = defs->hello_holdtime; + ei->hello_interval = defs->hello_interval; + ei->delay = defs->delay; + ei->bandwidth = defs->bandwidth; + ei->splithorizon = defs->splithorizon; + ei = NULL; + defs = &asdefs; + } + ; + +interface_block : '{' optnl interfaceopts_l '}' + | '{' optnl '}' + | + ; + +interfaceopts_l : interfaceopts_l interfaceoptsl nl + | interfaceoptsl optnl + ; + +interfaceoptsl : PASSIVE { ei->passive = 1; } + | SUMMARY_ADDR STRING { + struct summary_addr *s; + + if ((s = calloc(1, sizeof(*s))) == NULL) + fatal(NULL); + if (get_prefix($2, &s->prefix, &s->prefixlen) < 0) { + yyerror("invalid summary-address"); + free($2); + free(s); + YYERROR; + } + + free($2); + TAILQ_INSERT_TAIL(&ei->summary_list, s, entry); + } + | iface_defaults + ; + redistribute : no REDISTRIBUTE STRING opt_red_metric { struct redistribute *r; @@ -263,7 +387,7 @@ redistribute : no REDISTRIBUTE STRING opt_red_metric { r->type = REDIST_OSPF; else if (!strcmp($3, "connected")) r->type = REDIST_CONNECTED; - else if (host($3, &r->addr, &r->prefixlen) >= 0) + else if (get_prefix($3, &r->addr, &r->prefixlen) >= 0) r->type = REDIST_ADDR; else { yyerror("invalid redistribute"); @@ -322,8 +446,8 @@ redist_metric : NUMBER NUMBER NUMBER NUMBER NUMBER { } ; -opt_red_metric : /* empty */ { $$ = NULL; } - | METRIC redist_metric { $$ = $2; } +opt_red_metric : /* empty */ { $$ = NULL; } + | METRIC redist_metric { $$ = $2; } ; defaults : KVALUES NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER { @@ -426,130 +550,6 @@ iface_defaults : HELLOINTERVAL NUMBER { } ; -optnl : '\n' optnl - | - ; - -nl : '\n' optnl /* one newline or more */ - ; - -af : AF eigrp_af { - af = $2; - afdefs = *defs; - defs = &afdefs; - } af_block { - af = AF_UNSPEC; - defs = &globaldefs; - } - ; - -af_block : '{' optnl afopts_l '}' - | '{' optnl '}' - | - ; - -afopts_l : afopts_l afoptsl nl - | afoptsl optnl - ; - -afoptsl : as - | defaults - ; - -as : AS NUMBER { - if ($2 < EIGRP_MIN_AS || $2 > EIGRP_MAX_AS) { - yyerror("invalid autonomous-system"); - YYERROR; - } - eigrp = conf_get_instance($2); - if (eigrp == NULL) - YYERROR; - - asdefs = *defs; - defs = &asdefs; - } as_block { - memcpy(eigrp->kvalues, defs->kvalues, - sizeof(eigrp->kvalues)); - eigrp->active_timeout = defs->active_timeout; - eigrp->maximum_hops = defs->maximum_hops; - eigrp->maximum_paths = defs->maximum_paths; - eigrp->variance = defs->variance; - eigrp->dflt_metric = defs->dflt_metric; - eigrp = NULL; - defs = &afdefs; - } - ; - -as_block : '{' optnl asopts_l '}' - | '{' optnl '}' - | - ; - -asopts_l : asopts_l asoptsl nl - | asoptsl optnl - ; - -asoptsl : interface - | redistribute { - SIMPLEQ_INSERT_TAIL(&eigrp->redist_list, $1, entry); - } - | defaults - ; - -interface : INTERFACE STRING { - struct kif *kif; - - if ((kif = kif_findname($2)) == NULL) { - yyerror("unknown interface %s", $2); - free($2); - YYERROR; - } - free($2); - ei = conf_get_if(kif); - if (ei == NULL) - YYERROR; - - ifacedefs = *defs; - defs = &ifacedefs; - } interface_block { - ei->hello_holdtime = defs->hello_holdtime; - ei->hello_interval = defs->hello_interval; - ei->delay = defs->delay; - ei->bandwidth = defs->bandwidth; - ei->splithorizon = defs->splithorizon; - ei = NULL; - defs = &asdefs; - } - ; - -interface_block : '{' optnl interfaceopts_l '}' - | '{' optnl '}' - | - ; - -interfaceopts_l : interfaceopts_l interfaceoptsl nl - | interfaceoptsl optnl - ; - -interfaceoptsl : PASSIVE { ei->passive = 1; } - | SUMMARY_ADDR STRING { - struct summary_addr *s; - - if ((s = calloc(1, sizeof(*s))) == NULL) - fatal(NULL); - if (host($2, &s->prefix, &s->prefixlen) < 0) { - yyerror("invalid summary-address"); - free($2); - free(s); - YYERROR; - } - - free($2); - TAILQ_INSERT_TAIL(&ei->summary_list, s, entry); - } - | iface_defaults - ; - %% struct keywords { @@ -1163,7 +1163,7 @@ get_rtr_id(void) } int -host(const char *s, union eigrpd_addr *addr, uint8_t *plen) +get_prefix(const char *s, union eigrpd_addr *addr, uint8_t *plen) { char *p, *ps; const char *errstr; @@ -1187,11 +1187,11 @@ host(const char *s, union eigrpd_addr *addr, uint8_t *plen) return (-1); } if ((ps = malloc(strlen(s) - strlen(p) + 1)) == NULL) - fatal("host: malloc"); + fatal("get_prefix: malloc"); strlcpy(ps, s, strlen(s) - strlen(p) + 1); } else { if ((ps = strdup(s)) == NULL) - fatal("host: strdup"); + fatal("get_prefix: strdup"); *plen = maxplen; } diff --git a/usr.sbin/eigrpd/rde_dual.c b/usr.sbin/eigrpd/rde_dual.c index 9569b1fd663..92fb8eb5cfb 100644 --- a/usr.sbin/eigrpd/rde_dual.c +++ b/usr.sbin/eigrpd/rde_dual.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_dual.c,v 1.22 2016/02/21 18:56:49 renato Exp $ */ +/* $OpenBSD: rde_dual.c,v 1.23 2016/02/21 19:01:12 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -1277,7 +1277,7 @@ rde_nbr_new(uint32_t peerid, struct rde_nbr *new) nbr->peerid = peerid; nbr->ifaceid = new->ifaceid; nbr->addr = new->addr; - nbr->ei = eigrp_iface_find_id(nbr->ifaceid); + nbr->ei = eigrp_if_lookup_id(nbr->ifaceid); if (nbr->ei) nbr->eigrp = nbr->ei->eigrp; TAILQ_INIT(&nbr->rijk); |