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

Commit 494fff56 authored by Yuval Mintz's avatar Yuval Mintz Committed by David S. Miller
Browse files

ipmr, ip6mr: Make mfc_cache a common structure



mfc_cache and mfc6_cache are almost identical - the main difference is
in the origin/group addresses and comparison-key. Make a common
structure encapsulating most of the multicast routing logic  - mr_mfc
and convert both ipmr and ip6mr into using it.

For easy conversion [casting, in this case] mr_mfc has to be the first
field inside every multicast routing abstraction utilizing it.

Signed-off-by: default avatarYuval Mintz <yuvalm@mellanox.com>
Acked-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0bbbf0e7
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -126,8 +126,8 @@ mlxsw_sp_mr_route_ivif_in_evifs(const struct mlxsw_sp_mr_route *mr_route)

	switch (mr_route->mr_table->proto) {
	case MLXSW_SP_L3_PROTO_IPV4:
		ivif = mr_route->mfc4->mfc_parent;
		return mr_route->mfc4->mfc_un.res.ttls[ivif] != 255;
		ivif = mr_route->mfc4->_c.mfc_parent;
		return mr_route->mfc4->_c.mfc_un.res.ttls[ivif] != 255;
	case MLXSW_SP_L3_PROTO_IPV6:
		/* fall through */
	default:
@@ -364,7 +364,7 @@ mlxsw_sp_mr_route4_create(struct mlxsw_sp_mr_table *mr_table,
	mr_route->mfc4 = mfc;
	mr_route->mr_table = mr_table;
	for (i = 0; i < MAXVIFS; i++) {
		if (mfc->mfc_un.res.ttls[i] != 255) {
		if (mfc->_c.mfc_un.res.ttls[i] != 255) {
			err = mlxsw_sp_mr_route_evif_link(mr_route,
							  &mr_table->vifs[i]);
			if (err)
@@ -374,7 +374,8 @@ mlxsw_sp_mr_route4_create(struct mlxsw_sp_mr_table *mr_table,
				mr_route->min_mtu = mr_table->vifs[i].dev->mtu;
		}
	}
	mlxsw_sp_mr_route_ivif_link(mr_route, &mr_table->vifs[mfc->mfc_parent]);
	mlxsw_sp_mr_route_ivif_link(mr_route,
				    &mr_table->vifs[mfc->_c.mfc_parent]);

	mr_route->route_action = mlxsw_sp_mr_route_action(mr_route);
	return mr_route;
@@ -418,9 +419,9 @@ static void mlxsw_sp_mr_mfc_offload_set(struct mlxsw_sp_mr_route *mr_route,
	switch (mr_route->mr_table->proto) {
	case MLXSW_SP_L3_PROTO_IPV4:
		if (offload)
			mr_route->mfc4->mfc_flags |= MFC_OFFLOAD;
			mr_route->mfc4->_c.mfc_flags |= MFC_OFFLOAD;
		else
			mr_route->mfc4->mfc_flags &= ~MFC_OFFLOAD;
			mr_route->mfc4->_c.mfc_flags &= ~MFC_OFFLOAD;
		break;
	case MLXSW_SP_L3_PROTO_IPV6:
		/* fall through */
@@ -943,10 +944,10 @@ static void mlxsw_sp_mr_route_stats_update(struct mlxsw_sp *mlxsw_sp,

	switch (mr_route->mr_table->proto) {
	case MLXSW_SP_L3_PROTO_IPV4:
		if (mr_route->mfc4->mfc_un.res.pkt != packets)
			mr_route->mfc4->mfc_un.res.lastuse = jiffies;
		mr_route->mfc4->mfc_un.res.pkt = packets;
		mr_route->mfc4->mfc_un.res.bytes = bytes;
		if (mr_route->mfc4->_c.mfc_un.res.pkt != packets)
			mr_route->mfc4->_c.mfc_un.res.lastuse = jiffies;
		mr_route->mfc4->_c.mfc_un.res.pkt = packets;
		mr_route->mfc4->_c.mfc_un.res.bytes = bytes;
		break;
	case MLXSW_SP_L3_PROTO_IPV6:
		/* fall through */
+4 −41
Original line number Diff line number Diff line
@@ -81,28 +81,13 @@ struct mfc_cache_cmp_arg {

/**
 * struct mfc_cache - multicast routing entries
 * @mnode: rhashtable list
 * @_c: Common multicast routing information; has to be first [for casting]
 * @mfc_mcastgrp: destination multicast group address
 * @mfc_origin: source address
 * @cmparg: used for rhashtable comparisons
 * @mfc_parent: source interface (iif)
 * @mfc_flags: entry flags
 * @expires: unresolved entry expire time
 * @unresolved: unresolved cached skbs
 * @last_assert: time of last assert
 * @minvif: minimum VIF id
 * @maxvif: maximum VIF id
 * @bytes: bytes that have passed for this entry
 * @pkt: packets that have passed for this entry
 * @wrong_if: number of wrong source interface hits
 * @lastuse: time of last use of the group (traffic or update)
 * @ttls: OIF TTL threshold array
 * @refcount: reference count for this entry
 * @list: global entry list
 * @rcu: used for entry destruction
 */
struct mfc_cache {
	struct rhlist_head mnode;
	struct mr_mfc _c;
	union {
		struct {
			__be32 mfc_mcastgrp;
@@ -110,28 +95,6 @@ struct mfc_cache {
		};
		struct mfc_cache_cmp_arg cmparg;
	};
	vifi_t mfc_parent;
	int mfc_flags;

	union {
		struct {
			unsigned long expires;
			struct sk_buff_head unresolved;
		} unres;
		struct {
			unsigned long last_assert;
			int minvif;
			int maxvif;
			unsigned long bytes;
			unsigned long pkt;
			unsigned long wrong_if;
			unsigned long lastuse;
			unsigned char ttls[MAXVIFS];
			refcount_t refcount;
		} res;
	} mfc_un;
	struct list_head list;
	struct rcu_head	rcu;
};

struct mfc_entry_notifier_info {
@@ -155,12 +118,12 @@ static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)

static inline void ipmr_cache_put(struct mfc_cache *c)
{
	if (refcount_dec_and_test(&c->mfc_un.res.refcount))
	if (refcount_dec_and_test(&c->_c.mfc_un.res.refcount))
		ipmr_cache_free(c);
}
static inline void ipmr_cache_hold(struct mfc_cache *c)
{
	refcount_inc(&c->mfc_un.res.refcount);
	refcount_inc(&c->_c.mfc_un.res.refcount);
}

#endif
+1 −22
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ struct mfc6_cache_cmp_arg {
};

struct mfc6_cache {
	struct rhlist_head mnode;
	struct mr_mfc _c;
	union {
		struct {
			struct in6_addr mf6c_mcastgrp;
@@ -79,27 +79,6 @@ struct mfc6_cache {
		};
		struct mfc6_cache_cmp_arg cmparg;
	};
	mifi_t mf6c_parent;			/* Source interface		*/
	int mfc_flags;				/* Flags on line		*/

	union {
		struct {
			unsigned long expires;
			struct sk_buff_head unresolved;	/* Unresolved buffers		*/
		} unres;
		struct {
			unsigned long last_assert;
			int minvif;
			int maxvif;
			unsigned long bytes;
			unsigned long pkt;
			unsigned long wrong_if;
			unsigned long lastuse;
			unsigned char ttls[MAXMIFS];	/* TTL thresholds		*/
		} res;
	} mfc_un;
	struct list_head list;
	struct rcu_head rcu;
};

#define MFC_STATIC		1
+45 −0
Original line number Diff line number Diff line
@@ -44,6 +44,51 @@ struct vif_device {

#define VIF_EXISTS(_mrt, _idx) (!!((_mrt)->vif_table[_idx].dev))

/**
 * struct mr_mfc - common multicast routing entries
 * @mnode: rhashtable list
 * @mfc_parent: source interface (iif)
 * @mfc_flags: entry flags
 * @expires: unresolved entry expire time
 * @unresolved: unresolved cached skbs
 * @last_assert: time of last assert
 * @minvif: minimum VIF id
 * @maxvif: maximum VIF id
 * @bytes: bytes that have passed for this entry
 * @pkt: packets that have passed for this entry
 * @wrong_if: number of wrong source interface hits
 * @lastuse: time of last use of the group (traffic or update)
 * @ttls: OIF TTL threshold array
 * @refcount: reference count for this entry
 * @list: global entry list
 * @rcu: used for entry destruction
 */
struct mr_mfc {
	struct rhlist_head mnode;
	unsigned short mfc_parent;
	int mfc_flags;

	union {
		struct {
			unsigned long expires;
			struct sk_buff_head unresolved;
		} unres;
		struct {
			unsigned long last_assert;
			int minvif;
			int maxvif;
			unsigned long bytes;
			unsigned long pkt;
			unsigned long wrong_if;
			unsigned long lastuse;
			unsigned char ttls[MAXVIFS];
			refcount_t refcount;
		} res;
	} mfc_un;
	struct list_head list;
	struct rcu_head	rcu;
};

/**
 * struct mr_table - a multicast routing table
 * @list: entry within a list of multicast routing tables
+125 −108

File changed.

Preview size limit exceeded, changes collapsed.

Loading