60 #include <netlink-private/netlink.h>
61 #include <netlink/netlink.h>
62 #include <netlink/attr.h>
63 #include <netlink/route/rtnl.h>
64 #include <netlink-private/route/link/api.h>
69 uint8_t i_confset[IPV4_DEVCONF_MAX];
70 uint32_t i_conf[IPV4_DEVCONF_MAX];
74 static void *inet_alloc(
struct rtnl_link *link)
76 return calloc(1,
sizeof(
struct inet_data));
79 static void *inet_clone(
struct rtnl_link *link,
void *data)
83 if ((
id = inet_alloc(link)))
84 memcpy(
id, data,
sizeof(*
id));
89 static void inet_free(
struct rtnl_link *link,
void *data)
94 static struct nla_policy inet_policy[IFLA_INET6_MAX+1] = {
95 [IFLA_INET_CONF] = { .
minlen = 4 },
98 static int inet_parse_af(
struct rtnl_link *link,
struct nlattr *attr,
void *data)
100 struct inet_data *
id = data;
101 struct nlattr *tb[IFLA_INET_MAX+1];
107 if (tb[IFLA_INET_CONF] &&
nla_len(tb[IFLA_INET_CONF]) % 4)
110 if (tb[IFLA_INET_CONF]) {
112 int len = min_t(
int, IPV4_DEVCONF_MAX,
nla_len(tb[IFLA_INET_CONF]) / 4);
114 for (i = 0; i < len; i++)
115 id->i_confset[i] = 1;
116 nla_memcpy(&id->i_conf, tb[IFLA_INET_CONF],
sizeof(id->i_conf));
122 static int inet_fill_af(
struct rtnl_link *link,
struct nl_msg *msg,
void *data)
124 struct inet_data *
id = data;
131 for (i = 0; i < IPV4_DEVCONF_MAX; i++)
132 if (id->i_confset[i])
143 static const struct trans_tbl inet_devconf[] = {
144 __ADD(IPV4_DEVCONF_FORWARDING, forwarding)
145 __ADD(IPV4_DEVCONF_MC_FORWARDING, mc_forwarding)
146 __ADD(IPV4_DEVCONF_PROXY_ARP, proxy_arp)
147 __ADD(IPV4_DEVCONF_ACCEPT_REDIRECTS, accept_redirects)
148 __ADD(IPV4_DEVCONF_SECURE_REDIRECTS, secure_redirects)
149 __ADD(IPV4_DEVCONF_SEND_REDIRECTS, send_redirects)
150 __ADD(IPV4_DEVCONF_SHARED_MEDIA, shared_media)
151 __ADD(IPV4_DEVCONF_RP_FILTER, rp_filter)
152 __ADD(IPV4_DEVCONF_ACCEPT_SOURCE_ROUTE, accept_source_route)
153 __ADD(IPV4_DEVCONF_BOOTP_RELAY, bootp_relay)
154 __ADD(IPV4_DEVCONF_LOG_MARTIANS, log_martians)
155 __ADD(IPV4_DEVCONF_TAG, tag)
156 __ADD(IPV4_DEVCONF_ARPFILTER, arpfilter)
157 __ADD(IPV4_DEVCONF_MEDIUM_ID, medium_id)
158 __ADD(IPV4_DEVCONF_NOXFRM, noxfrm)
159 __ADD(IPV4_DEVCONF_NOPOLICY, nopolicy)
160 __ADD(IPV4_DEVCONF_FORCE_IGMP_VERSION, force_igmp_version)
161 __ADD(IPV4_DEVCONF_ARP_ANNOUNCE, arp_announce)
162 __ADD(IPV4_DEVCONF_ARP_IGNORE, arp_ignore)
163 __ADD(IPV4_DEVCONF_PROMOTE_SECONDARIES, promote_secondaries)
164 __ADD(IPV4_DEVCONF_ARP_ACCEPT, arp_accept)
165 __ADD(IPV4_DEVCONF_ARP_NOTIFY, arp_notify)
166 __ADD(IPV4_DEVCONF_ACCEPT_LOCAL, accept_local)
167 __ADD(IPV4_DEVCONF_SRC_VMARK, src_vmark)
168 __ADD(IPV4_DEVCONF_PROXY_ARP_PVLAN, proxy_arp_pvlan)
169 __ADD(IPV4_DEVCONF_ROUTE_LOCALNET, route_localnet)
170 __ADD(IPV4_DEVCONF_IGMPV2_UNSOLICITED_REPORT_INTERVAL, igmpv2_unsolicited_report_interval)
171 __ADD(IPV4_DEVCONF_IGMPV3_UNSOLICITED_REPORT_INTERVAL, igmpv3_unsolicited_report_interval)
174 const
char *rtnl_link_inet_devconf2str(
int type,
char *buf,
size_t len)
176 return __type2str(type, buf, len, inet_devconf,
177 ARRAY_SIZE(inet_devconf));
180 int rtnl_link_inet_str2devconf(
const char *name)
182 return __str2type(name, inet_devconf, ARRAY_SIZE(inet_devconf));
185 static void inet_dump_details(
struct rtnl_link *link,
188 struct inet_data *
id = data;
192 nl_dump_line(p,
" ipv4 devconf:\n");
193 nl_dump_line(p,
" ");
195 for (i = 0; i < IPV4_DEVCONF_MAX; i++) {
196 nl_dump_line(p,
"%-19s %3u",
197 rtnl_link_inet_devconf2str(i+1, buf,
sizeof(buf)),
198 id->i_confset[i] ? id->i_conf[i] : 0);
202 nl_dump_line(p,
" ");
212 static struct rtnl_link_af_ops inet_ops = {
213 .ao_family = AF_INET,
214 .ao_alloc = &inet_alloc,
215 .ao_clone = &inet_clone,
216 .ao_free = &inet_free,
217 .ao_parse_af = &inet_parse_af,
218 .ao_fill_af = &inet_fill_af,
240 struct inet_data *id;
242 if (cfgid == 0 || cfgid > IPV4_DEVCONF_MAX)
248 if (!id->i_confset[cfgid - 1])
250 *res =
id->i_conf[cfgid - 1];
270 struct inet_data *id;
275 if (cfgid == 0 || cfgid > IPV4_DEVCONF_MAX)
278 id->i_confset[cfgid - 1] = 1;
279 id->i_conf[cfgid - 1] = value;
285 static void __init inet_init(
void)
290 static void __exit inet_exit(
void)
int rtnl_link_af_register(struct rtnl_link_af_ops *ops)
Register operations for a link address family.
Attribute validation policy.
int rtnl_link_af_unregister(struct rtnl_link_af_ops *ops)
Unregister operations for a link address family.
Dump all attributes but no statistics.
int nla_memcpy(void *dest, struct nlattr *src, int count)
Copy attribute payload to another memory area.
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, struct nla_policy *policy)
Create attribute index based on nested attribute.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
int nla_len(const struct nlattr *nla)
Return length of the payload .
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.
uint16_t minlen
Minimal length of payload required.
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.
struct nlattr * nla_nest_start(struct nl_msg *msg, int attrtype)
Start a new level of nested attributes.
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.