Skip to content

Commit c985018

Browse files
jpirkodavem330
authored andcommitted
fib: introduce FIB info offload flag helpers
These helpers are to be used in case someone offloads the FIB entry. The result is that if the entry is offloaded to at least one device, the offload flag is set. Signed-off-by: Jiri Pirko <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b90eb75 commit c985018

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

include/net/ip_fib.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct fib_info {
123123
#ifdef CONFIG_IP_ROUTE_MULTIPATH
124124
int fib_weight;
125125
#endif
126+
unsigned int fib_offload_cnt;
126127
struct rcu_head rcu;
127128
struct fib_nh fib_nh[0];
128129
#define fib_dev fib_nh[0].nh_dev
@@ -174,6 +175,18 @@ struct fib_result_nl {
174175

175176
__be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
176177

178+
static inline void fib_info_offload_inc(struct fib_info *fi)
179+
{
180+
fi->fib_offload_cnt++;
181+
fi->fib_flags |= RTNH_F_OFFLOAD;
182+
}
183+
184+
static inline void fib_info_offload_dec(struct fib_info *fi)
185+
{
186+
if (--fi->fib_offload_cnt == 0)
187+
fi->fib_flags &= ~RTNH_F_OFFLOAD;
188+
}
189+
177190
#define FIB_RES_SADDR(net, res) \
178191
((FIB_RES_NH(res).nh_saddr_genid == \
179192
atomic_read(&(net)->ipv4.dev_addr_genid)) ? \

net/switchdev/switchdev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
12161216
ipv4_fib.obj.orig_dev = dev;
12171217
err = switchdev_port_obj_add(dev, &ipv4_fib.obj);
12181218
if (!err)
1219-
fi->fib_flags |= RTNH_F_OFFLOAD;
1219+
fib_info_offload_inc(fi);
12201220

12211221
return err == -EOPNOTSUPP ? 0 : err;
12221222
}
@@ -1260,7 +1260,7 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
12601260
ipv4_fib.obj.orig_dev = dev;
12611261
err = switchdev_port_obj_del(dev, &ipv4_fib.obj);
12621262
if (!err)
1263-
fi->fib_flags &= ~RTNH_F_OFFLOAD;
1263+
fib_info_offload_dec(fi);
12641264

12651265
return err == -EOPNOTSUPP ? 0 : err;
12661266
}

0 commit comments

Comments
 (0)