aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/fib_semantics.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2015-08-31 09:58:44 -0400
committerDavid S. Miller <davem@davemloft.net>2015-08-31 15:34:00 -0400
commit6cf9dfd3bd62edfff69f11c0f111bc261166e4c7 (patch)
treea19d1ff89446023388fcd70c3dcb2525ccc7404e /net/ipv4/fib_semantics.c
parent87583ebb9f6ea6dc7f8ef167b815656787e429fc (diff)
net: fib: move metrics parsing to a helper
fib_create_info() is already quite large, so before adding more code to the metrics section move that to a helper, similar to ip6_convert_metrics. Suggested-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/fib_semantics.c')
-rw-r--r--net/ipv4/fib_semantics.c71
1 files changed, 41 insertions, 30 deletions
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 1b2d01170a4d..88afbae893f0 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -876,6 +876,44 @@ static bool fib_valid_prefsrc(struct fib_config *cfg, __be32 fib_prefsrc)
876 return true; 876 return true;
877} 877}
878 878
879static int
880fib_convert_metrics(struct fib_info *fi, const struct fib_config *cfg)
881{
882 struct nlattr *nla;
883 int remaining;
884
885 if (!cfg->fc_mx)
886 return 0;
887
888 nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) {
889 int type = nla_type(nla);
890 u32 val;
891
892 if (!type)
893 continue;
894 if (type > RTAX_MAX)
895 return -EINVAL;
896
897 if (type == RTAX_CC_ALGO) {
898 char tmp[TCP_CA_NAME_MAX];
899
900 nla_strlcpy(tmp, nla, sizeof(tmp));
901 val = tcp_ca_get_key_by_name(tmp);
902 if (val == TCP_CA_UNSPEC)
903 return -EINVAL;
904 } else {
905 val = nla_get_u32(nla);
906 }
907 if (type == RTAX_ADVMSS && val > 65535 - 40)
908 val = 65535 - 40;
909 if (type == RTAX_MTU && val > 65535 - 15)
910 val = 65535 - 15;
911 fi->fib_metrics[type - 1] = val;
912 }
913
914 return 0;
915}
916
879struct fib_info *fib_create_info(struct fib_config *cfg) 917struct fib_info *fib_create_info(struct fib_config *cfg)
880{ 918{
881 int err; 919 int err;
@@ -948,36 +986,9 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
948 goto failure; 986 goto failure;
949 } endfor_nexthops(fi) 987 } endfor_nexthops(fi)
950 988
951 if (cfg->fc_mx) { 989 err = fib_convert_metrics(fi, cfg);
952 struct nlattr *nla; 990 if (err)
953 int remaining; 991 goto failure;
954
955 nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) {
956 int type = nla_type(nla);
957
958 if (type) {
959 u32 val;
960
961 if (type > RTAX_MAX)
962 goto err_inval;
963 if (type == RTAX_CC_ALGO) {
964 char tmp[TCP_CA_NAME_MAX];
965
966 nla_strlcpy(tmp, nla, sizeof(tmp));
967 val = tcp_ca_get_key_by_name(tmp);
968 if (val == TCP_CA_UNSPEC)
969 goto err_inval;
970 } else {
971 val = nla_get_u32(nla);
972 }
973 if (type == RTAX_ADVMSS && val > 65535 - 40)
974 val = 65535 - 40;
975 if (type == RTAX_MTU && val > 65535 - 15)
976 val = 65535 - 15;
977 fi->fib_metrics[type - 1] = val;
978 }
979 }
980 }
981 992
982 if (cfg->fc_mp) { 993 if (cfg->fc_mp) {
983#ifdef CONFIG_IP_ROUTE_MULTIPATH 994#ifdef CONFIG_IP_ROUTE_MULTIPATH