Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 47dcf0cb authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller
Browse files

[NET]: Rethink mark field in struct flowi



Now that all protocols have been made aware of the mark
field it can be moved out of the union thus simplyfing
its usage.

The config options in the IPv4/IPv6/DECnet subsystems
to enable respectively disable mark based routing only
obfuscate the code with ifdefs, the cost for the
additional comparison in the flow key is insignificant,
and most distributions have all these options enabled
by default anyway. Therefore it makes sense to remove
the config options and enable mark based routing by
default.

Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 82e91ffe
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -13,12 +13,12 @@
struct flowi {
	int	oif;
	int	iif;
	__u32	mark;

	union {
		struct {
			__be32			daddr;
			__be32			saddr;
			__u32			fwmark;
			__u8			tos;
			__u8			scope;
		} ip4_u;
@@ -26,28 +26,23 @@ struct flowi {
		struct {
			struct in6_addr		daddr;
			struct in6_addr		saddr;
			__u32			fwmark;
			__be32			flowlabel;
		} ip6_u;

		struct {
			__le16			daddr;
			__le16			saddr;
			__u32			fwmark;
			__u8			scope;
		} dn_u;
	} nl_u;
#define fld_dst		nl_u.dn_u.daddr
#define fld_src		nl_u.dn_u.saddr
#define fld_fwmark	nl_u.dn_u.fwmark
#define fld_scope	nl_u.dn_u.scope
#define fl6_dst		nl_u.ip6_u.daddr
#define fl6_src		nl_u.ip6_u.saddr
#define fl6_fwmark	nl_u.ip6_u.fwmark
#define fl6_flowlabel	nl_u.ip6_u.flowlabel
#define fl4_dst		nl_u.ip4_u.daddr
#define fl4_src		nl_u.ip4_u.saddr
#define fl4_fwmark	nl_u.ip4_u.fwmark
#define fl4_tos		nl_u.ip4_u.tos
#define fl4_scope	nl_u.ip4_u.scope

+1 −3
Original line number Diff line number Diff line
@@ -88,9 +88,7 @@ static inline int multipath_comparekeys(const struct flowi *flp1,
	return flp1->fl4_dst == flp2->fl4_dst &&
		flp1->fl4_src == flp2->fl4_src &&
		flp1->oif == flp2->oif &&
#ifdef CONFIG_IP_ROUTE_FWMARK
		flp1->fl4_fwmark == flp2->fl4_fwmark &&
#endif
		flp1->mark == flp2->mark &&
		!((flp1->fl4_tos ^ flp2->fl4_tos) &
		  (IPTOS_RT_MASK | RTO_ONLINK));
}
+0 −8
Original line number Diff line number Diff line
@@ -41,11 +41,3 @@ config DECNET_ROUTER

	  See <file:Documentation/networking/decnet.txt> for more information.
config DECNET_ROUTE_FWMARK
	bool "DECnet: use FWMARK value as routing key (EXPERIMENTAL)"
	depends on DECNET_ROUTER && NETFILTER
	help
	  If you say Y here, you will be able to specify different routes for
	  packets with different FWMARK ("firewalling mark") values
	  (see ipchains(8), "-m" argument).
+8 −20
Original line number Diff line number Diff line
@@ -269,9 +269,7 @@ static inline int compare_keys(struct flowi *fl1, struct flowi *fl2)
{
	return ((fl1->nl_u.dn_u.daddr ^ fl2->nl_u.dn_u.daddr) |
		(fl1->nl_u.dn_u.saddr ^ fl2->nl_u.dn_u.saddr) |
#ifdef CONFIG_DECNET_ROUTE_FWMARK
		(fl1->nl_u.dn_u.fwmark ^ fl2->nl_u.dn_u.fwmark) |
#endif
		(fl1->mark ^ fl2->mark) |
		(fl1->nl_u.dn_u.scope ^ fl2->nl_u.dn_u.scope) |
		(fl1->oif ^ fl2->oif) |
		(fl1->iif ^ fl2->iif)) == 0;
@@ -882,10 +880,8 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
				      { .daddr = oldflp->fld_dst,
					.saddr = oldflp->fld_src,
					.scope = RT_SCOPE_UNIVERSE,
#ifdef CONFIG_DECNET_ROUTE_FWMARK
					.fwmark = oldflp->fld_fwmark
#endif
				     } },
			    .mark = oldflp->mark,
			    .iif = loopback_dev.ifindex,
			    .oif = oldflp->oif };
	struct dn_route *rt = NULL;
@@ -903,7 +899,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
		       "dn_route_output_slow: dst=%04x src=%04x mark=%d"
		       " iif=%d oif=%d\n", dn_ntohs(oldflp->fld_dst),
		       dn_ntohs(oldflp->fld_src),
                       oldflp->fld_fwmark, loopback_dev.ifindex, oldflp->oif);
                       oldflp->mark, loopback_dev.ifindex, oldflp->oif);

	/* If we have an output interface, verify its a DECnet device */
	if (oldflp->oif) {
@@ -1108,9 +1104,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
	rt->fl.fld_dst    = oldflp->fld_dst;
	rt->fl.oif        = oldflp->oif;
	rt->fl.iif        = 0;
#ifdef CONFIG_DECNET_ROUTE_FWMARK
	rt->fl.fld_fwmark = oldflp->fld_fwmark;
#endif
	rt->fl.mark       = oldflp->mark;

	rt->rt_saddr      = fl.fld_src;
	rt->rt_daddr      = fl.fld_dst;
@@ -1178,9 +1172,7 @@ static int __dn_route_output_key(struct dst_entry **pprt, const struct flowi *fl
			rt = rcu_dereference(rt->u.rt_next)) {
			if ((flp->fld_dst == rt->fl.fld_dst) &&
			    (flp->fld_src == rt->fl.fld_src) &&
#ifdef CONFIG_DECNET_ROUTE_FWMARK
			    (flp->fld_fwmark == rt->fl.fld_fwmark) &&
#endif
			    (flp->mark == rt->fl.mark) &&
			    (rt->fl.iif == 0) &&
			    (rt->fl.oif == flp->oif)) {
				rt->u.dst.lastuse = jiffies;
@@ -1235,10 +1227,8 @@ static int dn_route_input_slow(struct sk_buff *skb)
				     { .daddr = cb->dst,
				       .saddr = cb->src,
				       .scope = RT_SCOPE_UNIVERSE,
#ifdef CONFIG_DECNET_ROUTE_FWMARK
				       .fwmark = skb->mark
#endif
				    } },
			    .mark = skb->mark,
			    .iif = skb->dev->ifindex };
	struct dn_fib_res res = { .fi = NULL, .type = RTN_UNREACHABLE };
	int err = -EINVAL;
@@ -1385,7 +1375,7 @@ static int dn_route_input_slow(struct sk_buff *skb)
	rt->fl.fld_dst    = cb->dst;
	rt->fl.oif        = 0;
	rt->fl.iif        = in_dev->ifindex;
	rt->fl.fld_fwmark = fl.fld_fwmark;
	rt->fl.mark       = fl.mark;

	rt->u.dst.flags = DST_HOST;
	rt->u.dst.neighbour = neigh;
@@ -1457,9 +1447,7 @@ int dn_route_input(struct sk_buff *skb)
		if ((rt->fl.fld_src == cb->src) &&
	 	    (rt->fl.fld_dst == cb->dst) &&
		    (rt->fl.oif == 0) &&
#ifdef CONFIG_DECNET_ROUTE_FWMARK
		    (rt->fl.fld_fwmark == skb->mark) &&
#endif
		    (rt->fl.mark == skb->mark) &&
		    (rt->fl.iif == cb->iif)) {
			rt->u.dst.lastuse = jiffies;
			dst_hold(&rt->u.dst);
+1 −11
Original line number Diff line number Diff line
@@ -45,10 +45,8 @@ struct dn_fib_rule
	__le16			dstmask;
	__le16			srcmap;
	u8			flags;
#ifdef CONFIG_DECNET_ROUTE_FWMARK
	u32			fwmark;
	u32			fwmask;
#endif
};

static struct dn_fib_rule default_rule = {
@@ -131,10 +129,8 @@ static int dn_fib_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
	    ((daddr ^ r->dst) & r->dstmask))
		return 0;

#ifdef CONFIG_DECNET_ROUTE_FWMARK
	if ((r->fwmark ^ fl->fld_fwmark) & r->fwmask)
	if ((r->fwmark ^ fl->mark) & r->fwmask)
		return 0;
#endif

	return 1;
}
@@ -169,7 +165,6 @@ static int dn_fib_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
	if (tb[FRA_DST])
		r->dst = nla_get_u16(tb[FRA_DST]);

#ifdef CONFIG_DECNET_ROUTE_FWMARK
	if (tb[FRA_FWMARK]) {
		r->fwmark = nla_get_u32(tb[FRA_FWMARK]);
		if (r->fwmark)
@@ -181,7 +176,6 @@ static int dn_fib_rule_configure(struct fib_rule *rule, struct sk_buff *skb,

	if (tb[FRA_FWMASK])
		r->fwmask = nla_get_u32(tb[FRA_FWMASK]);
#endif

	r->src_len = frh->src_len;
	r->srcmask = dnet_make_mask(r->src_len);
@@ -203,13 +197,11 @@ static int dn_fib_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh,
	if (frh->dst_len && (r->dst_len != frh->dst_len))
		return 0;

#ifdef CONFIG_DECNET_ROUTE_FWMARK
	if (tb[FRA_FWMARK] && (r->fwmark != nla_get_u32(tb[FRA_FWMARK])))
		return 0;

	if (tb[FRA_FWMASK] && (r->fwmask != nla_get_u32(tb[FRA_FWMASK])))
		return 0;
#endif

	if (tb[FRA_SRC] && (r->src != nla_get_u16(tb[FRA_SRC])))
		return 0;
@@ -248,12 +240,10 @@ static int dn_fib_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
	frh->src_len = r->src_len;
	frh->tos = 0;

#ifdef CONFIG_DECNET_ROUTE_FWMARK
	if (r->fwmark)
		NLA_PUT_U32(skb, FRA_FWMARK, r->fwmark);
	if (r->fwmask || r->fwmark)
		NLA_PUT_U32(skb, FRA_FWMASK, r->fwmask);
#endif
	if (r->dst_len)
		NLA_PUT_U16(skb, FRA_DST, r->dst);
	if (r->src_len)
Loading