Skip to content

Commit c6f55fb

Browse files
committed
zebra: intf address handler is platform-neutral
Move the handler for incoming interface address events to a neutral source file - it's not netlink-specific and shouldn't have been in a netlink file. Signed-off-by: Mark Stapp <mjs.ietf@gmail.com>
1 parent d166308 commit c6f55fb

3 files changed

Lines changed: 98 additions & 116 deletions

File tree

zebra/if_netlink.c

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,114 +1662,6 @@ int netlink_interface_addr_dplane(struct nlmsghdr *h, ns_id_t ns_id,
16621662
return 0;
16631663
}
16641664

1665-
/*
1666-
* Handle an interface addr event based on info in a dplane context object.
1667-
* This runs in the main pthread, using the info in the context object to
1668-
* modify an interface.
1669-
*/
1670-
int netlink_interface_addr_ctx(struct zebra_dplane_ctx *ctx)
1671-
{
1672-
int ret = -1;
1673-
struct interface *ifp;
1674-
uint8_t flags = 0;
1675-
const char *label = NULL;
1676-
ns_id_t ns_id;
1677-
struct zebra_ns *zns;
1678-
uint32_t metric = METRIC_MAX;
1679-
ifindex_t ifindex;
1680-
const struct prefix *addr, *dest = NULL;
1681-
enum dplane_op_e op;
1682-
1683-
op = dplane_ctx_get_op(ctx);
1684-
ns_id = dplane_ctx_get_ns_id(ctx);
1685-
1686-
zns = zebra_ns_lookup(ns_id);
1687-
if (zns == NULL) {
1688-
/* No ns - deleted maybe? */
1689-
if (IS_ZEBRA_DEBUG_KERNEL)
1690-
zlog_debug("%s: can't find zns id %u", __func__, ns_id);
1691-
goto done;
1692-
}
1693-
1694-
ifindex = dplane_ctx_get_ifindex(ctx);
1695-
1696-
ifp = if_lookup_by_index_per_ns(zns, ifindex);
1697-
if (ifp == NULL) {
1698-
if (IS_ZEBRA_DEBUG_KERNEL)
1699-
zlog_debug("%s: can't find ifp at nsid %u index %d",
1700-
__func__, ns_id, ifindex);
1701-
goto done;
1702-
}
1703-
1704-
addr = dplane_ctx_get_intf_addr(ctx);
1705-
1706-
if (IS_ZEBRA_DEBUG_KERNEL)
1707-
zlog_debug("%s: %s: ifindex %u, addr %pFX", __func__,
1708-
dplane_op2str(op), ifindex, addr);
1709-
1710-
/* Is there a peer or broadcast address? */
1711-
dest = dplane_ctx_get_intf_dest(ctx);
1712-
if (dest->prefixlen == 0)
1713-
dest = NULL;
1714-
1715-
if (dplane_ctx_intf_is_connected(ctx))
1716-
SET_FLAG(flags, ZEBRA_IFA_PEER);
1717-
1718-
/* Flags. */
1719-
if (dplane_ctx_intf_is_secondary(ctx))
1720-
SET_FLAG(flags, ZEBRA_IFA_SECONDARY);
1721-
1722-
/* Label? */
1723-
if (dplane_ctx_intf_has_label(ctx))
1724-
label = dplane_ctx_get_intf_label(ctx);
1725-
1726-
if (label && strcmp(ifp->name, label) == 0)
1727-
label = NULL;
1728-
1729-
metric = dplane_ctx_get_intf_metric(ctx);
1730-
1731-
/* Register interface address to the interface. */
1732-
if (addr->family == AF_INET) {
1733-
if (op == DPLANE_OP_INTF_ADDR_ADD)
1734-
connected_add_ipv4(
1735-
ifp, flags, &addr->u.prefix4, addr->prefixlen,
1736-
dest ? &dest->u.prefix4 : NULL, label, metric);
1737-
else if (CHECK_FLAG(flags, ZEBRA_IFA_PEER)) {
1738-
/* Delete with a peer address */
1739-
connected_delete_ipv4(ifp, flags, &addr->u.prefix4,
1740-
addr->prefixlen,
1741-
&dest->u.prefix4);
1742-
} else
1743-
connected_delete_ipv4(ifp, flags, &addr->u.prefix4,
1744-
addr->prefixlen, NULL);
1745-
}
1746-
1747-
if (addr->family == AF_INET6) {
1748-
if (op == DPLANE_OP_INTF_ADDR_ADD) {
1749-
connected_add_ipv6(ifp, flags, &addr->u.prefix6,
1750-
dest ? &dest->u.prefix6 : NULL,
1751-
addr->prefixlen, label, metric);
1752-
} else
1753-
connected_delete_ipv6(ifp, &addr->u.prefix6, NULL,
1754-
addr->prefixlen);
1755-
}
1756-
1757-
/*
1758-
* Linux kernel does not send route delete on interface down/addr del
1759-
* so we have to re-process routes it owns (i.e. kernel routes)
1760-
*/
1761-
if (op != DPLANE_OP_INTF_ADDR_ADD)
1762-
rib_update(RIB_UPDATE_KERNEL);
1763-
1764-
ret = 0;
1765-
1766-
done:
1767-
/* We're responsible for the ctx object */
1768-
dplane_ctx_fini(&ctx);
1769-
1770-
return ret;
1771-
}
1772-
17731665
int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
17741666
{
17751667
int len;

zebra/if_netlink.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ extern int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id,
3737
int netlink_interface_addr_dplane(struct nlmsghdr *h, ns_id_t ns_id,
3838
int startup);
3939

40-
/* Handle an interface addr change event. */
41-
int netlink_interface_addr_ctx(struct zebra_dplane_ctx *ctx);
42-
4340
extern int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup);
4441
extern int interface_lookup_netlink(struct zebra_ns *zns);
4542

zebra/interface.c

Lines changed: 98 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,14 +1205,107 @@ void zebra_if_set_protodown(struct interface *ifp, bool down)
12051205
#endif
12061206
}
12071207

1208-
/* Handler for incoming intf address change events */
1208+
/*
1209+
* Handle an interface addr event based on info in a dplane context object.
1210+
* This runs in the main pthread, using the info in the context object to
1211+
* modify an interface.
1212+
*/
12091213
void zebra_if_addr_update_ctx(struct zebra_dplane_ctx *ctx)
12101214
{
1211-
#ifdef HAVE_NETLINK
1212-
netlink_interface_addr_ctx(ctx);
1213-
#else
1215+
struct interface *ifp;
1216+
uint8_t flags = 0;
1217+
const char *label = NULL;
1218+
ns_id_t ns_id;
1219+
struct zebra_ns *zns;
1220+
uint32_t metric = METRIC_MAX;
1221+
ifindex_t ifindex;
1222+
const struct prefix *addr, *dest = NULL;
1223+
enum dplane_op_e op;
1224+
1225+
op = dplane_ctx_get_op(ctx);
1226+
ns_id = dplane_ctx_get_ns_id(ctx);
1227+
1228+
zns = zebra_ns_lookup(ns_id);
1229+
if (zns == NULL) {
1230+
/* No ns - deleted maybe? */
1231+
if (IS_ZEBRA_DEBUG_KERNEL)
1232+
zlog_debug("%s: can't find zns id %u", __func__, ns_id);
1233+
goto done;
1234+
}
1235+
1236+
ifindex = dplane_ctx_get_ifindex(ctx);
1237+
1238+
ifp = if_lookup_by_index_per_ns(zns, ifindex);
1239+
if (ifp == NULL) {
1240+
if (IS_ZEBRA_DEBUG_KERNEL)
1241+
zlog_debug("%s: can't find ifp at nsid %u index %d",
1242+
__func__, ns_id, ifindex);
1243+
goto done;
1244+
}
1245+
1246+
addr = dplane_ctx_get_intf_addr(ctx);
1247+
1248+
if (IS_ZEBRA_DEBUG_KERNEL)
1249+
zlog_debug("%s: %s: ifindex %u, addr %pFX", __func__,
1250+
dplane_op2str(op), ifindex, addr);
1251+
1252+
/* Is there a peer or broadcast address? */
1253+
dest = dplane_ctx_get_intf_dest(ctx);
1254+
if (dest->prefixlen == 0)
1255+
dest = NULL;
1256+
1257+
if (dplane_ctx_intf_is_connected(ctx))
1258+
SET_FLAG(flags, ZEBRA_IFA_PEER);
1259+
1260+
/* Flags. */
1261+
if (dplane_ctx_intf_is_secondary(ctx))
1262+
SET_FLAG(flags, ZEBRA_IFA_SECONDARY);
1263+
1264+
/* Label? */
1265+
if (dplane_ctx_intf_has_label(ctx))
1266+
label = dplane_ctx_get_intf_label(ctx);
1267+
1268+
if (label && strcmp(ifp->name, label) == 0)
1269+
label = NULL;
1270+
1271+
metric = dplane_ctx_get_intf_metric(ctx);
1272+
1273+
/* Register interface address to the interface. */
1274+
if (addr->family == AF_INET) {
1275+
if (op == DPLANE_OP_INTF_ADDR_ADD)
1276+
connected_add_ipv4(
1277+
ifp, flags, &addr->u.prefix4, addr->prefixlen,
1278+
dest ? &dest->u.prefix4 : NULL, label, metric);
1279+
else if (CHECK_FLAG(flags, ZEBRA_IFA_PEER)) {
1280+
/* Delete with a peer address */
1281+
connected_delete_ipv4(ifp, flags, &addr->u.prefix4,
1282+
addr->prefixlen,
1283+
&dest->u.prefix4);
1284+
} else
1285+
connected_delete_ipv4(ifp, flags, &addr->u.prefix4,
1286+
addr->prefixlen, NULL);
1287+
}
1288+
1289+
if (addr->family == AF_INET6) {
1290+
if (op == DPLANE_OP_INTF_ADDR_ADD) {
1291+
connected_add_ipv6(ifp, flags, &addr->u.prefix6,
1292+
dest ? &dest->u.prefix6 : NULL,
1293+
addr->prefixlen, label, metric);
1294+
} else
1295+
connected_delete_ipv6(ifp, &addr->u.prefix6, NULL,
1296+
addr->prefixlen);
1297+
}
1298+
1299+
/*
1300+
* Linux kernel does not send route delete on interface down/addr del
1301+
* so we have to re-process routes it owns (i.e. kernel routes)
1302+
*/
1303+
if (op != DPLANE_OP_INTF_ADDR_ADD)
1304+
rib_update(RIB_UPDATE_KERNEL);
1305+
1306+
done:
1307+
/* We're responsible for the ctx object */
12141308
dplane_ctx_fini(&ctx);
1215-
#endif /* HAVE_NETLINK */
12161309
}
12171310

12181311
/* Dump if address information to vty. */

0 commit comments

Comments
 (0)