|
| 1 | +/* |
| 2 | + * lib/route/link/bridge_info.c bridge info support |
| 3 | + * |
| 4 | + * This library is free software; you can redistribute it and/or |
| 5 | + * modify it under the terms of the GNU Lesser General Public |
| 6 | + * License as published by the Free Software Foundation version 2.1 |
| 7 | + * of the License. |
| 8 | + * |
| 9 | + * Copyright (c) 2022 MaxLinear, Inc. |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * @ingroup link |
| 14 | + * @defgroup bridge Bridging |
| 15 | + * |
| 16 | + * @details |
| 17 | + * @{ |
| 18 | + */ |
| 19 | + |
| 20 | +#include <netlink-private/netlink.h> |
| 21 | +#include <netlink-private/route/link/api.h> |
| 22 | + |
| 23 | +struct bridge_info |
| 24 | +{ |
| 25 | + uint32_t ce_mask; /* to support attr macros */ |
| 26 | +}; |
| 27 | + |
| 28 | +static struct nla_policy bi_attrs_policy[IFLA_BR_MAX+1] = { |
| 29 | + |
| 30 | +}; |
| 31 | + |
| 32 | +static inline struct bridge_info *bridge_info(struct rtnl_link *link) |
| 33 | +{ |
| 34 | + return link->l_info; |
| 35 | +} |
| 36 | + |
| 37 | +static int bridge_info_alloc(struct rtnl_link *link) |
| 38 | +{ |
| 39 | + struct bridge_info *bi; |
| 40 | + |
| 41 | + if (link->l_info) |
| 42 | + memset(link->l_info, 0, sizeof(*bi)); |
| 43 | + else { |
| 44 | + bi = calloc(1, sizeof(*bi)); |
| 45 | + if (!bi) |
| 46 | + return -NLE_NOMEM; |
| 47 | + |
| 48 | + link->l_info = bi; |
| 49 | + } |
| 50 | + |
| 51 | + return 0; |
| 52 | +} |
| 53 | + |
| 54 | +static int bridge_info_parse(struct rtnl_link *link, struct nlattr *data, |
| 55 | + struct nlattr *xstats) |
| 56 | +{ |
| 57 | + struct nlattr *tb[IFLA_BR_MAX+1]; |
| 58 | + struct bridge_info *bi; |
| 59 | + int err = 0; |
| 60 | + |
| 61 | + NL_DBG(3, "Parsing Bridge link info\n"); |
| 62 | + |
| 63 | + if ((err = nla_parse_nested(tb, IFLA_BR_MAX, data, bi_attrs_policy)) < 0) |
| 64 | + goto errout; |
| 65 | + |
| 66 | + if ((err = bridge_info_alloc(link)) < 0) |
| 67 | + goto errout; |
| 68 | + |
| 69 | + bi = link->l_info; |
| 70 | + |
| 71 | +errout: |
| 72 | + return err; |
| 73 | +} |
| 74 | + |
| 75 | +static int bridge_info_put_attrs(struct nl_msg *msg, struct rtnl_link *link) |
| 76 | +{ |
| 77 | + struct bridge_info *bi = link->l_info; |
| 78 | + struct nlattr *data; |
| 79 | + |
| 80 | + data = nla_nest_start(msg, IFLA_INFO_DATA); |
| 81 | + if (!data) |
| 82 | + return -NLE_MSGSIZE; |
| 83 | + |
| 84 | + nla_nest_end(msg, data); |
| 85 | + return 0; |
| 86 | +} |
| 87 | + |
| 88 | +static void bridge_info_free(struct rtnl_link *link) |
| 89 | +{ |
| 90 | + free(link->l_info); |
| 91 | + link->l_info = NULL; |
| 92 | +} |
| 93 | + |
| 94 | +static struct rtnl_link_info_ops bridge_info_ops = { |
| 95 | + .io_name = "bridge", |
| 96 | + .io_alloc = bridge_info_alloc, |
| 97 | + .io_parse = bridge_info_parse, |
| 98 | + .io_put_attrs = bridge_info_put_attrs, |
| 99 | + .io_free = bridge_info_free, |
| 100 | +}; |
| 101 | + |
| 102 | +#define IS_BRIDGE_INFO_ASSERT(link) \ |
| 103 | + do { \ |
| 104 | + if ((link)->l_info_ops != &bridge_info_ops) { \ |
| 105 | + APPBUG("Link is not a bridge link. Set type \"bridge\" first."); \ |
| 106 | + } \ |
| 107 | + } while(0) |
| 108 | + |
| 109 | +static void __init bridge_info_init(void) |
| 110 | +{ |
| 111 | + rtnl_link_register_info(&bridge_info_ops); |
| 112 | +} |
| 113 | + |
| 114 | +static void __exit bridge_info_exit(void) |
| 115 | +{ |
| 116 | + rtnl_link_unregister_info(&bridge_info_ops); |
| 117 | +} |
| 118 | + |
| 119 | +/** @} */ |
0 commit comments