54#include <netlink-private/netlink.h>
55#include <netlink/netlink.h>
56#include <netlink/attr.h>
57#include <netlink/route/rtnl.h>
58#include <netlink/route/link/inet.h>
59#include <netlink-private/route/link/api.h>
64 uint8_t i_confset[IPV4_DEVCONF_MAX];
65 uint32_t i_conf[IPV4_DEVCONF_MAX];
69static void *inet_alloc(
struct rtnl_link *link)
71 return calloc(1,
sizeof(
struct inet_data));
74static void *inet_clone(
struct rtnl_link *link,
void *data)
78 if ((
id = inet_alloc(link)))
79 memcpy(
id, data,
sizeof(*
id));
84static void inet_free(
struct rtnl_link *link,
void *data)
89static struct nla_policy inet_policy[IFLA_INET_MAX+1] = {
90 [IFLA_INET_CONF] = { .
minlen = 4 },
93static int inet_parse_af(
struct rtnl_link *link,
struct nlattr *attr,
void *data)
95 struct inet_data *
id = data;
96 struct nlattr *tb[IFLA_INET_MAX+1];
102 if (tb[IFLA_INET_CONF] &&
nla_len(tb[IFLA_INET_CONF]) % 4)
105 if (tb[IFLA_INET_CONF]) {
107 int len = min_t(
int, IPV4_DEVCONF_MAX,
nla_len(tb[IFLA_INET_CONF]) / 4);
109 for (i = 0; i < len; i++)
110 id->i_confset[i] = 1;
111 nla_memcpy(&id->i_conf, tb[IFLA_INET_CONF],
sizeof(id->i_conf));
117static int inet_fill_af(
struct rtnl_link *link,
struct nl_msg *msg,
void *data)
119 struct inet_data *
id = data;
126 for (i = 0; i < IPV4_DEVCONF_MAX; i++)
127 if (id->i_confset[i])
138static const struct trans_tbl inet_devconf[] = {
139 __ADD(IPV4_DEVCONF_FORWARDING, forwarding),
140 __ADD(IPV4_DEVCONF_MC_FORWARDING, mc_forwarding),
141 __ADD(IPV4_DEVCONF_PROXY_ARP, proxy_arp),
142 __ADD(IPV4_DEVCONF_ACCEPT_REDIRECTS, accept_redirects),
143 __ADD(IPV4_DEVCONF_SECURE_REDIRECTS, secure_redirects),
144 __ADD(IPV4_DEVCONF_SEND_REDIRECTS, send_redirects),
145 __ADD(IPV4_DEVCONF_SHARED_MEDIA, shared_media),
146 __ADD(IPV4_DEVCONF_RP_FILTER, rp_filter),
147 __ADD(IPV4_DEVCONF_ACCEPT_SOURCE_ROUTE, accept_source_route),
148 __ADD(IPV4_DEVCONF_BOOTP_RELAY, bootp_relay),
149 __ADD(IPV4_DEVCONF_LOG_MARTIANS, log_martians),
150 __ADD(IPV4_DEVCONF_TAG, tag),
151 __ADD(IPV4_DEVCONF_ARPFILTER, arpfilter),
152 __ADD(IPV4_DEVCONF_MEDIUM_ID, medium_id),
153 __ADD(IPV4_DEVCONF_NOXFRM, noxfrm),
154 __ADD(IPV4_DEVCONF_NOPOLICY, nopolicy),
155 __ADD(IPV4_DEVCONF_FORCE_IGMP_VERSION, force_igmp_version),
156 __ADD(IPV4_DEVCONF_ARP_ANNOUNCE, arp_announce),
157 __ADD(IPV4_DEVCONF_ARP_IGNORE, arp_ignore),
158 __ADD(IPV4_DEVCONF_PROMOTE_SECONDARIES, promote_secondaries),
159 __ADD(IPV4_DEVCONF_ARP_ACCEPT, arp_accept),
160 __ADD(IPV4_DEVCONF_ARP_NOTIFY, arp_notify),
161 __ADD(IPV4_DEVCONF_ACCEPT_LOCAL, accept_local),
162 __ADD(IPV4_DEVCONF_SRC_VMARK, src_vmark),
163 __ADD(IPV4_DEVCONF_PROXY_ARP_PVLAN, proxy_arp_pvlan),
164 __ADD(IPV4_DEVCONF_ROUTE_LOCALNET, route_localnet),
165 __ADD(IPV4_DEVCONF_IGMPV2_UNSOLICITED_REPORT_INTERVAL, igmpv2_unsolicited_report_interval),
166 __ADD(IPV4_DEVCONF_IGMPV3_UNSOLICITED_REPORT_INTERVAL, igmpv3_unsolicited_report_interval),
169const char *rtnl_link_inet_devconf2str(
int type,
char *buf,
size_t len)
171 return __type2str(type, buf, len, inet_devconf,
172 ARRAY_SIZE(inet_devconf));
175int rtnl_link_inet_str2devconf(
const char *name)
177 return __str2type(name, inet_devconf, ARRAY_SIZE(inet_devconf));
180static void inet_dump_details(
struct rtnl_link *link,
183 struct inet_data *
id = data;
187 nl_dump_line(p,
" ipv4 devconf:\n");
188 nl_dump_line(p,
" ");
190 for (i = 0; i < IPV4_DEVCONF_MAX; i++) {
191 nl_dump_line(p,
"%-19s %3u",
192 rtnl_link_inet_devconf2str(i+1, buf,
sizeof(buf)),
193 id->i_confset[i] ? id->i_conf[i] : 0);
197 nl_dump_line(p,
" ");
207static struct rtnl_link_af_ops inet_ops = {
208 .ao_family = AF_INET,
209 .ao_alloc = &inet_alloc,
210 .ao_clone = &inet_clone,
211 .ao_free = &inet_free,
212 .ao_parse_af = &inet_parse_af,
213 .ao_fill_af = &inet_fill_af,
235 struct inet_data *id;
237 if (cfgid == 0 || cfgid > IPV4_DEVCONF_MAX)
243 if (!id->i_confset[cfgid - 1])
245 *res =
id->i_conf[cfgid - 1];
265 struct inet_data *id;
270 if (cfgid == 0 || cfgid > IPV4_DEVCONF_MAX)
273 id->i_confset[cfgid - 1] = 1;
274 id->i_conf[cfgid - 1] = value;
280static void __init inet_init(
void)
285static void __exit inet_exit(
void)
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
int nla_memcpy(void *dest, const struct nlattr *src, int count)
Copy attribute payload to another memory area.
struct nlattr * nla_nest_start(struct nl_msg *msg, int attrtype)
Start a new level of nested attributes.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy)
Create attribute index based on nested attribute.
int nla_len(const struct nlattr *nla)
Return length of the payload .
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
void * rtnl_link_af_alloc(struct rtnl_link *link, const struct rtnl_link_af_ops *ops)
Allocate and return data buffer for link address family modules.
int rtnl_link_af_unregister(struct rtnl_link_af_ops *ops)
Unregister operations for a link address family.
int rtnl_link_af_register(struct rtnl_link_af_ops *ops)
Register operations for a link address family.
void * rtnl_link_af_data(const struct rtnl_link *link, const struct rtnl_link_af_ops *ops)
Return data buffer for link address family modules.
int rtnl_link_inet_get_conf(struct rtnl_link *link, const unsigned int cfgid, uint32_t *res)
Get value of a ipv4 link configuration setting.
int rtnl_link_inet_set_conf(struct rtnl_link *link, const unsigned int cfgid, uint32_t value)
Change value of a ipv4 link configuration setting.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Attribute validation policy.
uint16_t minlen
Minimal length of payload required.