-/* $OpenBSD: kroute.c,v 1.217 2017/11/29 19:40:47 claudio Exp $ */
+/* $OpenBSD: kroute.c,v 1.218 2018/07/10 13:06:28 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
if ((kr_state.fd = socket(AF_ROUTE,
SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) == -1) {
- log_warn("kr_init: socket");
+ log_warn("%s: socket", __func__);
return (-1);
}
/* not interested in my own messages */
if (setsockopt(kr_state.fd, SOL_SOCKET, SO_USELOOPBACK,
&opt, sizeof(opt)) == -1)
- log_warn("kr_init: setsockopt"); /* not fatal */
+ log_warn("%s: setsockopt", __func__); /* not fatal */
/* grow receive buffer, don't wanna miss messages */
optlen = sizeof(default_rcvbuf);
if (getsockopt(kr_state.fd, SOL_SOCKET, SO_RCVBUF,
&default_rcvbuf, &optlen) == -1)
- log_warn("kr_init getsockopt SOL_SOCKET SO_RCVBUF");
+ log_warn("%s: getsockopt SOL_SOCKET SO_RCVBUF", __func__);
else
for (rcvbuf = MAX_RTSOCK_BUF;
rcvbuf > default_rcvbuf &&
if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_TABLEFILTER, &tid,
sizeof(tid)) == -1) {
- log_warn("kr_init: setsockopt AF_ROUTE ROUTE_TABLEFILTER");
+ log_warn("%s: setsockopt AF_ROUTE ROUTE_TABLEFILTER", __func__);
return (-1);
}
oldsize = sizeof(struct ktable *) * krt_size;
if ((xkrt = reallocarray(krt, rtableid + 1,
sizeof(struct ktable *))) == NULL) {
- log_warn("ktable_new");
+ log_warn("%s", __func__);
return (-1);
}
krt = xkrt;
/* allocate new element */
kt = krt[rtableid] = calloc(1, sizeof(struct ktable));
if (kt == NULL) {
- log_warn("ktable_new");
+ log_warn("%s", __func__);
return (-1);
}
/* everything is up and running */
kt->state = RECONF_REINIT;
- log_debug("new ktable %s for rtableid %d", name, rtableid);
+ log_debug("%s: %s for rtableid %d", __func__, name, rtableid);
return (0);
}
/* decouple just to be sure, does not hurt */
kr_fib_decouple(kt->rtableid, fib_prio);
- log_debug("freeing ktable %s rtableid %u", kt->descr, kt->rtableid);
+ log_debug("%s: freeing ktable %s rtableid %u", __func__, kt->descr,
+ kt->rtableid);
knexthop_clear(kt);
kroute_clear(kt);
kroute6_clear(kt);
if (errno == ENOENT)
/* table nonexistent */
return (0);
- log_warn("sysctl");
+ log_warn("%s: sysctl", __func__);
/* must return 0 so that the table is considered non-existent */
return (0);
}
case AID_VPN_IPv4:
return (krVPN4_change(kt, kl, fib_prio));
}
- log_warnx("kr_change: not handled AID");
+ log_warnx("%s: not handled AID", __func__);
return (-1);
}
if (action == RTM_ADD) {
if ((kr = calloc(1, sizeof(struct kroute_node))) == NULL) {
- log_warn("kr_change");
+ log_warn("%s", __func__);
return (-1);
}
kr->r.prefix.s_addr = kl->prefix.v4.s_addr;
if (action == RTM_ADD) {
if ((kr6 = calloc(1, sizeof(struct kroute6_node))) == NULL) {
- log_warn("kr_change");
+ log_warn("%s", __func__);
return (-1);
}
memcpy(&kr6->r.prefix, &kl->prefix.v6, sizeof(struct in6_addr));
/* only single MPLS label are supported for now */
if (kl->prefix.vpn4.labellen != 3) {
- log_warnx("krVPN4_change: %s/%u has not a single label",
+ log_warnx("%s: %s/%u has not a single label", __func__,
log_addr(&kl->prefix), kl->prefixlen);
return (0);
}
if (action == RTM_ADD) {
if ((kr = calloc(1, sizeof(struct kroute_node))) == NULL) {
- log_warn("krVPN4_change");
+ log_warn("%s", __func__);
return (-1);
}
kr->r.prefix.s_addr = kl->prefix.vpn4.addr.s_addr;
rtableid = conf->default_tableid;
if ((kt = ktable_get(rtableid)) == NULL) {
- log_warnx("kr_nexthop_add: non-existent rtableid %d", rtableid);
+ log_warnx("%s: non-existent rtableid %d", __func__, rtableid);
return (0);
}
if ((h = knexthop_find(kt, addr)) != NULL) {
knexthop_send_update(h);
} else {
if ((h = calloc(1, sizeof(struct knexthop_node))) == NULL) {
- log_warn("kr_nexthop_add");
+ log_warn("%s", __func__);
return (-1);
}
memcpy(&h->nexthop, addr, sizeof(h->nexthop));
rtableid = conf->default_tableid;
if ((kt = ktable_get(rtableid)) == NULL) {
- log_warnx("kr_nexthop_delete: non-existent rtableid %d",
+ log_warnx("%s: non-existent rtableid %d", __func__,
rtableid);
return;
}
case IMSG_CTL_KROUTE:
if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(flags) +
sizeof(af)) {
- log_warnx("kr_show_route: wrong imsg len");
+ log_warnx("%s: wrong imsg len", __func__);
break;
}
kt = ktable_get(imsg->hdr.peerid);
if (kt == NULL) {
- log_warnx("kr_show_route: table %u does not exist",
+ log_warnx("%s: table %u does not exist", __func__,
imsg->hdr.peerid);
break;
}
case IMSG_CTL_KROUTE_ADDR:
if (imsg->hdr.len != IMSG_HEADER_SIZE +
sizeof(struct bgpd_addr)) {
- log_warnx("kr_show_route: wrong imsg len");
+ log_warnx("%s: wrong imsg len", __func__);
break;
}
kt = ktable_get(imsg->hdr.peerid);
if (kt == NULL) {
- log_warnx("kr_show_route: table %u does not exist",
+ log_warnx("%s: table %u does not exist", __func__,
imsg->hdr.peerid);
break;
}
case IMSG_CTL_SHOW_NEXTHOP:
kt = ktable_get(imsg->hdr.peerid);
if (kt == NULL) {
- log_warnx("kr_show_route: table %u does not exist",
+ log_warnx("%s: table %u does not exist", __func__,
imsg->hdr.peerid);
break;
}
struct ktable *kt;
if ((kt = ktable_get(rtableid)) == NULL) {
- log_warnx("kr_net_reload: non-existent rtableid %d", rtableid);
+ log_warnx("%s: non-existent rtableid %d", __func__, rtableid);
return (-1);
}
in_addr_t nexthop;
if (sa_in == NULL) {
- log_warnx("kroute_matchgw: no nexthop defined");
+ log_warnx("%s: no nexthop defined", __func__);
return (NULL);
}
nexthop = sa_in->sin_addr.s_addr;
struct knexthop_node *s;
if ((krm = RB_FIND(kroute_tree, &kt->krt, kr)) == NULL) {
- log_warnx("kroute_remove failed to find %s/%u",
+ log_warnx("%s: failed to find %s/%u", __func__,
inet_ntoa(kr->r.prefix), kr->r.prefixlen);
return (-1);
}
if (krm == kr) {
/* head element */
if (RB_REMOVE(kroute_tree, &kt->krt, kr) == NULL) {
- log_warnx("kroute_remove failed for %s/%u",
+ log_warnx("%s: failed for %s/%u", __func__,
inet_ntoa(kr->r.prefix), kr->r.prefixlen);
return (-1);
}
if (kr->next != NULL) {
if (RB_INSERT(kroute_tree, &kt->krt, kr->next) !=
NULL) {
- log_warnx("kroute_remove failed to add %s/%u",
+ log_warnx("%s: failed to add %s/%u", __func__,
inet_ntoa(kr->r.prefix), kr->r.prefixlen);
return (-1);
}
while (krm->next != kr && krm->next != NULL)
krm = krm->next;
if (krm->next == NULL) {
- log_warnx("kroute_remove multipath list corrupted "
- "for %s/%u", inet_ntoa(kr->r.prefix),
+ log_warnx("%s: multipath list corrupted "
+ "for %s/%u", inet_ntoa(kr->r.prefix), __func__,
kr->r.prefixlen);
return (-1);
}
struct in6_addr nexthop;
if (sa_in6 == NULL) {
- log_warnx("kroute6_matchgw: no nexthop defined");
+ log_warnx("%s: no nexthop defined", __func__);
return (NULL);
}
memcpy(&nexthop, &sa_in6->sin6_addr, sizeof(nexthop));
struct knexthop_node *s;
if ((krm = RB_FIND(kroute6_tree, &kt->krt6, kr)) == NULL) {
- log_warnx("kroute6_remove failed for %s/%u",
+ log_warnx("%s: failed for %s/%u", __func__,
log_in6addr(&kr->r.prefix), kr->r.prefixlen);
return (-1);
}
if (krm == kr) {
/* head element */
if (RB_REMOVE(kroute6_tree, &kt->krt6, kr) == NULL) {
- log_warnx("kroute6_remove failed for %s/%u",
+ log_warnx("%s: failed for %s/%u", __func__,
log_in6addr(&kr->r.prefix), kr->r.prefixlen);
return (-1);
}
if (kr->next != NULL) {
if (RB_INSERT(kroute6_tree, &kt->krt6, kr->next) !=
NULL) {
- log_warnx("kroute6_remove failed to add %s/%u",
+ log_warnx("%s: failed to add %s/%u", __func__,
log_in6addr(&kr->r.prefix),
kr->r.prefixlen);
return (-1);
while (krm->next != kr && krm->next != NULL)
krm = krm->next;
if (krm->next == NULL) {
- log_warnx("kroute6_remove multipath list corrupted "
- "for %s/%u", log_in6addr(&kr->r.prefix),
+ log_warnx("%s: multipath list corrupted "
+ "for %s/%u", __func__, log_in6addr(&kr->r.prefix),
kr->r.prefixlen);
return (-1);
}
knexthop_insert(struct ktable *kt, struct knexthop_node *kn)
{
if (RB_INSERT(knexthop_tree, KT2KNT(kt), kn) != NULL) {
- log_warnx("knexthop_insert failed for %s",
+ log_warnx("%s: failed for %s", __func__,
log_addr(&kn->nexthop));
free(kn);
return (-1);
kroute_detach_nexthop(kt, kn);
if (RB_REMOVE(knexthop_tree, KT2KNT(kt), kn) == NULL) {
- log_warnx("knexthop_remove failed for %s",
+ log_warnx("%s: failed for %s", __func__,
log_addr(&kn->nexthop));
return (-1);
}
kr->r.flags |= F_DOWN;
if ((kkr = calloc(1, sizeof(struct kif_kr))) == NULL) {
- log_warn("kif_kr_insert");
+ log_warn("%s", __func__);
return (-1);
}
; /* nothing */
if (kkr == NULL) {
- log_warnx("can't remove connected route from interface "
- "with index %u: not found", kr->r.ifindex);
+ log_warnx("%s: can't remove connected route from interface "
+ "with index %u: not found", __func__, kr->r.ifindex);
return (-1);
}
kr->r.flags |= F_DOWN;
if ((kkr6 = calloc(1, sizeof(struct kif_kr6))) == NULL) {
- log_warn("kif_kr6_insert");
+ log_warn("%s", __func__);
return (-1);
}
; /* nothing */
if (kkr6 == NULL) {
- log_warnx("can't remove connected route from interface "
- "with index %u: not found", kr->r.ifindex);
+ log_warnx("%s: can't remove connected route from interface "
+ "with index %u: not found", __func__, kr->r.ifindex);
return (-1);
}
/* special protection for 127/8 */
if ((kr = calloc(1, sizeof(struct kroute_node))) == NULL) {
- log_warn("protect_lo");
+ log_warn("%s", __func__);
return (-1);
}
kr->r.prefix.s_addr = htonl(INADDR_LOOPBACK & IN_CLASSA_NET);
/* special protection for loopback */
if ((kr6 = calloc(1, sizeof(struct kroute6_node))) == NULL) {
- log_warn("protect_lo");
+ log_warn("%s", __func__);
return (-1);
}
memcpy(&kr6->r.prefix, &in6addr_loopback, sizeof(kr6->r.prefix));
switch (ifan->ifan_what) {
case IFAN_ARRIVAL:
if ((kif = calloc(1, sizeof(struct kif_node))) == NULL) {
- log_warn("if_announce");
+ log_warn("%s", __func__);
return;
}
return (0);
}
}
- log_warn("send_rtmsg: action %u, prefix %s/%u", hdr.rtm_type,
+ log_warn("%s: action %u, prefix %s/%u", __func__, hdr.rtm_type,
inet_ntoa(kroute->prefix), kroute->prefixlen);
return (0);
}
return (0);
}
}
- log_warn("send_rt6msg: action %u, prefix %s/%u", hdr.rtm_type,
+ log_warn("%s: action %u, prefix %s/%u", __func__, hdr.rtm_type,
log_in6addr(&kroute->prefix), kroute->prefixlen);
return (0);
}
if (kt->rtableid != 0 && errno == EINVAL)
/* table nonexistent */
return (0);
- log_warn("sysctl");
+ log_warn("%s: sysctl", __func__);
return (-1);
}
if (len > 0) {
if ((buf = malloc(len)) == NULL) {
- log_warn("fetchtable");
+ log_warn("%s: fetchtable", __func__);
return (-1);
}
if (sysctl(mib, 7, buf, &len, NULL, 0) == -1) {
- log_warn("sysctl2");
+ log_warn("%s: sysctl2", __func__);
free(buf);
return (-1);
}
case AF_INET:
if ((kr = calloc(1, sizeof(struct kroute_node))) ==
NULL) {
- log_warn("fetchtable");
+ log_warn("%s", __func__);
free(buf);
return (-1);
}
case AF_INET6:
if ((kr6 = calloc(1, sizeof(struct kroute6_node))) ==
NULL) {
- log_warn("fetchtable");
+ log_warn("%s", __func__);
free(buf);
return (-1);
}
mib[5] = ifindex;
if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) {
- log_warn("sysctl");
+ log_warn("%s: sysctl", __func__);
return (-1);
}
if ((buf = malloc(len)) == NULL) {
- log_warn("fetchif");
+ log_warn("%s", __func__);
return (-1);
}
if (sysctl(mib, 6, buf, &len, NULL, 0) == -1) {
- log_warn("sysctl");
+ log_warn("%s: sysctl2", __func__);
free(buf);
return (-1);
}
get_rtaddrs(ifm.ifm_addrs, sa, rti_info);
if ((kif = calloc(1, sizeof(struct kif_node))) == NULL) {
- log_warn("fetchifs");
+ log_warn("%s", __func__);
free(buf);
return (-1);
}
if ((n = read(kr_state.fd, &buf, sizeof(buf))) == -1) {
if (errno == EAGAIN || errno == EINTR)
return (0);
- log_warn("dispatch_rtmsg: read error");
+ log_warn("%s: read error", __func__);
return (-1);
}
if (mpath)
/* get the correct route */
if ((kr = kroute_matchgw(kr, sa_in)) == NULL) {
- log_warnx("dispatch_rtmsg_addr[delete] "
- "mpath route not found");
+ log_warnx("%s[delete]: "
+ "mpath route not found", __func__);
return (0);
}
/* get the correct route */
if ((kr6 = kroute6_matchgw(kr6, sa_in6)) ==
NULL) {
- log_warnx("dispatch_rtmsg_addr[delete] "
- "IPv6 mpath route not found");
+ log_warnx("%s[delete]: IPv6 mpath "
+ "route not found", __func__);
return (0);
}
/* get the correct route */
if (mpath && rtm->rtm_type == RTM_CHANGE &&
(kr = kroute_matchgw(kr, sa_in)) == NULL) {
- log_warnx("dispatch_rtmsg_addr[change] "
- "mpath route not found");
+ log_warnx("%s[change]: "
+ "mpath route not found", __func__);
goto add4;
} else if (mpath && rtm->rtm_type == RTM_ADD)
goto add4;
knexthop_track(kt, kr);
}
} else if (rtm->rtm_type == RTM_CHANGE) {
- log_warnx("change req for %s/%u: not in table",
- log_addr(&prefix), prefixlen);
+ log_warnx("%s: change req for %s/%u: not in table",
+ __func__, log_addr(&prefix), prefixlen);
return (0);
} else {
add4:
if ((kr = calloc(1,
sizeof(struct kroute_node))) == NULL) {
- log_warn("dispatch_rtmsg");
+ log_warn("%s", __func__);
return (-1);
}
kr->r.prefix.s_addr = prefix.v4.s_addr;
if (mpath && rtm->rtm_type == RTM_CHANGE &&
(kr6 = kroute6_matchgw(kr6, sa_in6)) ==
NULL) {
- log_warnx("dispatch_rtmsg[change] "
- "IPv6 mpath route not found");
+ log_warnx("%s[change]: IPv6 mpath "
+ "route not found", __func__);
goto add6;
} else if (mpath && rtm->rtm_type == RTM_ADD)
goto add6;
knexthop_track(kt, kr6);
}
} else if (rtm->rtm_type == RTM_CHANGE) {
- log_warnx("change req for %s/%u: not in table",
- log_addr(&prefix), prefixlen);
+ log_warnx("%s: change req for %s/%u: not in table",
+ __func__, log_addr(&prefix), prefixlen);
return (0);
} else {
add6:
if ((kr6 = calloc(1,
sizeof(struct kroute6_node))) == NULL) {
- log_warn("dispatch_rtmsg_addr");
+ log_warn("%s", __func__);
return (-1);
}
memcpy(&kr6->r.prefix, &prefix.v6,