Skip to content

Commit a919525

Browse files
dsaherndavem330
authored andcommitted
net: Move fib_convert_metrics to metrics file
Move logic of fib_convert_metrics into ip_metrics_convert. This allows the code that converts netlink attributes into metrics struct to be re-used in a later patch by IPv6. This is mostly a code move with the following changes to variable names: - fi->fib_net becomes net - fc_mx and fc_mx_len are passed as inputs pulled from fib_config - metrics array is passed as an input from fi->fib_metrics->metrics Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a2d481b commit a919525

File tree

4 files changed

+60
-42
lines changed

4 files changed

+60
-42
lines changed

Diff for: include/net/ip.h

+3
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ static inline unsigned int ip_skb_dst_mtu(struct sock *sk,
396396
return min(READ_ONCE(skb_dst(skb)->dev->mtu), IP_MAX_MTU);
397397
}
398398

399+
int ip_metrics_convert(struct net *net, struct nlattr *fc_mx, int fc_mx_len,
400+
u32 *metrics);
401+
399402
u32 ip_idents_reserve(u32 hash, int segs);
400403
void __ip_select_ident(struct net *net, struct iphdr *iph, int segs);
401404

Diff for: net/ipv4/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ obj-y := route.o inetpeer.o protocol.o \
1313
tcp_offload.o datagram.o raw.o udp.o udplite.o \
1414
udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \
1515
fib_frontend.o fib_semantics.o fib_trie.o fib_notifier.o \
16-
inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o
16+
inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o \
17+
metrics.o
1718

1819
obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
1920
obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o

Diff for: net/ipv4/fib_semantics.c

+2-41
Original file line numberDiff line numberDiff line change
@@ -1019,47 +1019,8 @@ static bool fib_valid_prefsrc(struct fib_config *cfg, __be32 fib_prefsrc)
10191019
static int
10201020
fib_convert_metrics(struct fib_info *fi, const struct fib_config *cfg)
10211021
{
1022-
bool ecn_ca = false;
1023-
struct nlattr *nla;
1024-
int remaining;
1025-
1026-
if (!cfg->fc_mx)
1027-
return 0;
1028-
1029-
nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) {
1030-
int type = nla_type(nla);
1031-
u32 val;
1032-
1033-
if (!type)
1034-
continue;
1035-
if (type > RTAX_MAX)
1036-
return -EINVAL;
1037-
1038-
if (type == RTAX_CC_ALGO) {
1039-
char tmp[TCP_CA_NAME_MAX];
1040-
1041-
nla_strlcpy(tmp, nla, sizeof(tmp));
1042-
val = tcp_ca_get_key_by_name(fi->fib_net, tmp, &ecn_ca);
1043-
if (val == TCP_CA_UNSPEC)
1044-
return -EINVAL;
1045-
} else {
1046-
val = nla_get_u32(nla);
1047-
}
1048-
if (type == RTAX_ADVMSS && val > 65535 - 40)
1049-
val = 65535 - 40;
1050-
if (type == RTAX_MTU && val > 65535 - 15)
1051-
val = 65535 - 15;
1052-
if (type == RTAX_HOPLIMIT && val > 255)
1053-
val = 255;
1054-
if (type == RTAX_FEATURES && (val & ~RTAX_FEATURE_MASK))
1055-
return -EINVAL;
1056-
fi->fib_metrics->metrics[type - 1] = val;
1057-
}
1058-
1059-
if (ecn_ca)
1060-
fi->fib_metrics->metrics[RTAX_FEATURES - 1] |= DST_FEATURE_ECN_CA;
1061-
1062-
return 0;
1022+
return ip_metrics_convert(fi->fib_net, cfg->fc_mx, cfg->fc_mx_len,
1023+
fi->fib_metrics->metrics);
10631024
}
10641025

10651026
struct fib_info *fib_create_info(struct fib_config *cfg,

Diff for: net/ipv4/metrics.c

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <linux/netlink.h>
2+
#include <linux/rtnetlink.h>
3+
#include <linux/types.h>
4+
#include <net/ip.h>
5+
#include <net/net_namespace.h>
6+
#include <net/tcp.h>
7+
8+
int ip_metrics_convert(struct net *net, struct nlattr *fc_mx, int fc_mx_len,
9+
u32 *metrics)
10+
{
11+
bool ecn_ca = false;
12+
struct nlattr *nla;
13+
int remaining;
14+
15+
if (!fc_mx)
16+
return 0;
17+
18+
nla_for_each_attr(nla, fc_mx, fc_mx_len, remaining) {
19+
int type = nla_type(nla);
20+
u32 val;
21+
22+
if (!type)
23+
continue;
24+
if (type > RTAX_MAX)
25+
return -EINVAL;
26+
27+
if (type == RTAX_CC_ALGO) {
28+
char tmp[TCP_CA_NAME_MAX];
29+
30+
nla_strlcpy(tmp, nla, sizeof(tmp));
31+
val = tcp_ca_get_key_by_name(net, tmp, &ecn_ca);
32+
if (val == TCP_CA_UNSPEC)
33+
return -EINVAL;
34+
} else {
35+
val = nla_get_u32(nla);
36+
}
37+
if (type == RTAX_ADVMSS && val > 65535 - 40)
38+
val = 65535 - 40;
39+
if (type == RTAX_MTU && val > 65535 - 15)
40+
val = 65535 - 15;
41+
if (type == RTAX_HOPLIMIT && val > 255)
42+
val = 255;
43+
if (type == RTAX_FEATURES && (val & ~RTAX_FEATURE_MASK))
44+
return -EINVAL;
45+
metrics[type - 1] = val;
46+
}
47+
48+
if (ecn_ca)
49+
metrics[RTAX_FEATURES - 1] |= DST_FEATURE_ECN_CA;
50+
51+
return 0;
52+
}
53+
EXPORT_SYMBOL_GPL(ip_metrics_convert);

0 commit comments

Comments
 (0)