On Wed, Mar 27, 2019 at 08:53:48PM -0700, David Ahern wrote: > From: David Ahern <dsah...@gmail.com> > > Consolidate the fib_nh initialization which is duplicated between > fib_create_info for single path and fib_get_nhs for multipath. > Export the helper to allow for use with nexthop objects in the > future. > > Signed-off-by: David Ahern <dsah...@gmail.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com> One comment below. > +int fib_nh_init(struct net *net, struct fib_nh *nh, > + struct fib_config *cfg, int nh_weight, > + struct netlink_ext_ack *extack) > +{ > + int err = -ENOMEM; > + > + nh->nh_pcpu_rth_output = alloc_percpu(struct rtable __rcu *); > + if (!nh->nh_pcpu_rth_output) > + goto err_out; > + > + if (cfg->fc_encap) { > + struct lwtunnel_state *lwtstate; > + > + err = -EINVAL; > + if (cfg->fc_encap_type == LWTUNNEL_ENCAP_NONE) { > + NL_SET_ERR_MSG(extack, "LWT encap type not specified"); > + goto lwt_failure; > + } > + err = lwtunnel_build_state(cfg->fc_encap_type, > + cfg->fc_encap, AF_INET, cfg, > + &lwtstate, extack); > + if (err) > + goto lwt_failure; > + > + nh->nh_lwtstate = lwtstate_get(lwtstate); > + } > + > + nh->nh_oif = cfg->fc_oif; > + nh->nh_gw = cfg->fc_gw; > + nh->nh_flags = cfg->fc_flags; > + > +#ifdef CONFIG_IP_ROUTE_CLASSID > + nh->nh_tclassid = cfg->fc_flow; > + if (nh->nh_tclassid) > + net->ipv4.fib_num_tclassid_users++; > +#endif > +#ifdef CONFIG_IP_ROUTE_MULTIPATH > + nh->nh_weight = nh_weight; After this series 'nhc_weight' is always defined in the nexthop struct because it is shared with IPv6 which does not have a corresponding Kconfig. This ifdef can be removed from here and probably from a few other places as well. > +#endif > + return 0; > + > +lwt_failure: > + rt_fibinfo_free_cpus(nh->nh_pcpu_rth_output); > + nh->nh_pcpu_rth_output = NULL; > +err_out: > + return err; > +}