Commit 1e301fd0 authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

ipv4: Encapsulate function arguments in a struct

fib_dump_info() is used to prepare RTM_{NEW,DEL}ROUTE netlink messages
using the passed arguments. Currently, the function takes 11 arguments,
6 of which are attributes of the route being dumped (e.g., prefix, TOS).

The next patch will need the function to also dump to user space an
indication if the route is present in hardware or not. Instead of
passing yet another argument, change the function to take a struct
containing the different route attributes.

v2:
* Name last argument of fib_dump_info()
* Move 'struct fib_rt_info' to include/net/ip_fib.h so that it could
  later be passed to fib_alias_hw_flags_set()
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6324d0fa
...@@ -204,6 +204,15 @@ __be32 fib_result_prefsrc(struct net *net, struct fib_result *res); ...@@ -204,6 +204,15 @@ __be32 fib_result_prefsrc(struct net *net, struct fib_result *res);
#define FIB_RES_DEV(res) (FIB_RES_NHC(res)->nhc_dev) #define FIB_RES_DEV(res) (FIB_RES_NHC(res)->nhc_dev)
#define FIB_RES_OIF(res) (FIB_RES_NHC(res)->nhc_oif) #define FIB_RES_OIF(res) (FIB_RES_NHC(res)->nhc_oif)
struct fib_rt_info {
struct fib_info *fi;
u32 tb_id;
__be32 dst;
int dst_len;
u8 tos;
u8 type;
};
struct fib_entry_notifier_info { struct fib_entry_notifier_info {
struct fib_notifier_info info; /* must be first */ struct fib_notifier_info info; /* must be first */
u32 dst; u32 dst;
......
...@@ -35,9 +35,8 @@ struct fib_info *fib_create_info(struct fib_config *cfg, ...@@ -35,9 +35,8 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
int fib_nh_match(struct fib_config *cfg, struct fib_info *fi, int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
bool fib_metrics_match(struct fib_config *cfg, struct fib_info *fi); bool fib_metrics_match(struct fib_config *cfg, struct fib_info *fi);
int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event, u32 tb_id, int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
u8 type, __be32 dst, int dst_len, u8 tos, struct fib_info *fi, struct fib_rt_info *fri, unsigned int flags);
unsigned int);
void rtmsg_fib(int event, __be32 key, struct fib_alias *fa, int dst_len, void rtmsg_fib(int event, __be32 key, struct fib_alias *fa, int dst_len,
u32 tb_id, const struct nl_info *info, unsigned int nlm_flags); u32 tb_id, const struct nl_info *info, unsigned int nlm_flags);
......
...@@ -504,6 +504,7 @@ void rtmsg_fib(int event, __be32 key, struct fib_alias *fa, ...@@ -504,6 +504,7 @@ void rtmsg_fib(int event, __be32 key, struct fib_alias *fa,
int dst_len, u32 tb_id, const struct nl_info *info, int dst_len, u32 tb_id, const struct nl_info *info,
unsigned int nlm_flags) unsigned int nlm_flags)
{ {
struct fib_rt_info fri;
struct sk_buff *skb; struct sk_buff *skb;
u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0; u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0;
int err = -ENOBUFS; int err = -ENOBUFS;
...@@ -512,9 +513,13 @@ void rtmsg_fib(int event, __be32 key, struct fib_alias *fa, ...@@ -512,9 +513,13 @@ void rtmsg_fib(int event, __be32 key, struct fib_alias *fa,
if (!skb) if (!skb)
goto errout; goto errout;
err = fib_dump_info(skb, info->portid, seq, event, tb_id, fri.fi = fa->fa_info;
fa->fa_type, key, dst_len, fri.tb_id = tb_id;
fa->fa_tos, fa->fa_info, nlm_flags); fri.dst = key;
fri.dst_len = dst_len;
fri.tos = fa->fa_tos;
fri.type = fa->fa_type;
err = fib_dump_info(skb, info->portid, seq, event, &fri, nlm_flags);
if (err < 0) { if (err < 0) {
/* -EMSGSIZE implies BUG in fib_nlmsg_size() */ /* -EMSGSIZE implies BUG in fib_nlmsg_size() */
WARN_ON(err == -EMSGSIZE); WARN_ON(err == -EMSGSIZE);
...@@ -1725,10 +1730,11 @@ static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi) ...@@ -1725,10 +1730,11 @@ static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi)
#endif #endif
int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
u32 tb_id, u8 type, __be32 dst, int dst_len, u8 tos, struct fib_rt_info *fri, unsigned int flags)
struct fib_info *fi, unsigned int flags)
{ {
unsigned int nhs = fib_info_num_path(fi); unsigned int nhs = fib_info_num_path(fri->fi);
struct fib_info *fi = fri->fi;
u32 tb_id = fri->tb_id;
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
struct rtmsg *rtm; struct rtmsg *rtm;
...@@ -1738,22 +1744,22 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, ...@@ -1738,22 +1744,22 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
rtm = nlmsg_data(nlh); rtm = nlmsg_data(nlh);
rtm->rtm_family = AF_INET; rtm->rtm_family = AF_INET;
rtm->rtm_dst_len = dst_len; rtm->rtm_dst_len = fri->dst_len;
rtm->rtm_src_len = 0; rtm->rtm_src_len = 0;
rtm->rtm_tos = tos; rtm->rtm_tos = fri->tos;
if (tb_id < 256) if (tb_id < 256)
rtm->rtm_table = tb_id; rtm->rtm_table = tb_id;
else else
rtm->rtm_table = RT_TABLE_COMPAT; rtm->rtm_table = RT_TABLE_COMPAT;
if (nla_put_u32(skb, RTA_TABLE, tb_id)) if (nla_put_u32(skb, RTA_TABLE, tb_id))
goto nla_put_failure; goto nla_put_failure;
rtm->rtm_type = type; rtm->rtm_type = fri->type;
rtm->rtm_flags = fi->fib_flags; rtm->rtm_flags = fi->fib_flags;
rtm->rtm_scope = fi->fib_scope; rtm->rtm_scope = fi->fib_scope;
rtm->rtm_protocol = fi->fib_protocol; rtm->rtm_protocol = fi->fib_protocol;
if (rtm->rtm_dst_len && if (rtm->rtm_dst_len &&
nla_put_in_addr(skb, RTA_DST, dst)) nla_put_in_addr(skb, RTA_DST, fri->dst))
goto nla_put_failure; goto nla_put_failure;
if (fi->fib_priority && if (fi->fib_priority &&
nla_put_u32(skb, RTA_PRIORITY, fi->fib_priority)) nla_put_u32(skb, RTA_PRIORITY, fi->fib_priority))
......
...@@ -2194,14 +2194,18 @@ static int fn_trie_dump_leaf(struct key_vector *l, struct fib_table *tb, ...@@ -2194,14 +2194,18 @@ static int fn_trie_dump_leaf(struct key_vector *l, struct fib_table *tb,
if (filter->dump_routes) { if (filter->dump_routes) {
if (!s_fa) { if (!s_fa) {
struct fib_rt_info fri;
fri.fi = fi;
fri.tb_id = tb->tb_id;
fri.dst = xkey;
fri.dst_len = KEYLENGTH - fa->fa_slen;
fri.tos = fa->fa_tos;
fri.type = fa->fa_type;
err = fib_dump_info(skb, err = fib_dump_info(skb,
NETLINK_CB(cb->skb).portid, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
RTM_NEWROUTE, RTM_NEWROUTE, &fri, flags);
tb->tb_id, fa->fa_type,
xkey,
KEYLENGTH - fa->fa_slen,
fa->fa_tos, fi, flags);
if (err < 0) if (err < 0)
goto stop; goto stop;
} }
......
...@@ -3223,16 +3223,22 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, ...@@ -3223,16 +3223,22 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
if (rtm->rtm_flags & RTM_F_FIB_MATCH) { if (rtm->rtm_flags & RTM_F_FIB_MATCH) {
struct fib_rt_info fri;
if (!res.fi) { if (!res.fi) {
err = fib_props[res.type].error; err = fib_props[res.type].error;
if (!err) if (!err)
err = -EHOSTUNREACH; err = -EHOSTUNREACH;
goto errout_rcu; goto errout_rcu;
} }
fri.fi = res.fi;
fri.tb_id = table_id;
fri.dst = res.prefix;
fri.dst_len = res.prefixlen;
fri.tos = fl4.flowi4_tos;
fri.type = rt->rt_type;
err = fib_dump_info(skb, NETLINK_CB(in_skb).portid, err = fib_dump_info(skb, NETLINK_CB(in_skb).portid,
nlh->nlmsg_seq, RTM_NEWROUTE, table_id, nlh->nlmsg_seq, RTM_NEWROUTE, &fri, 0);
rt->rt_type, res.prefix, res.prefixlen,
fl4.flowi4_tos, res.fi, 0);
} else { } else {
err = rt_fill_info(net, dst, src, rt, table_id, &fl4, skb, err = rt_fill_info(net, dst, src, rt, table_id, &fl4, skb,
NETLINK_CB(in_skb).portid, NETLINK_CB(in_skb).portid,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment