Skip to content

Commit d8a566b

Browse files
kaberdavem330
authored andcommitted
net: fib_rules: consolidate IPv4 and DECnet ->default_pref() functions.
Both functions are equivalent, consolidate them since a following patch needs a third implementation for multicast routing. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5611551 commit d8a566b

4 files changed

Lines changed: 21 additions & 36 deletions

File tree

‎include/net/fib_rules.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ extern int fib_rules_lookup(struct fib_rules_ops *,
114114
extern int fib_default_rule_add(struct fib_rules_ops *,
115115
u32 pref, u32 table,
116116
u32 flags);
117+
extern u32 fib_default_rule_pref(struct fib_rules_ops *ops);
117118
#endif

‎net/core/fib_rules.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ int fib_default_rule_add(struct fib_rules_ops *ops,
3939
}
4040
EXPORT_SYMBOL(fib_default_rule_add);
4141

42+
u32 fib_default_rule_pref(struct fib_rules_ops *ops)
43+
{
44+
struct list_head *pos;
45+
struct fib_rule *rule;
46+
47+
if (!list_empty(&ops->rules_list)) {
48+
pos = ops->rules_list.next;
49+
if (pos->next != &ops->rules_list) {
50+
rule = list_entry(pos->next, struct fib_rule, list);
51+
if (rule->pref)
52+
return rule->pref - 1;
53+
}
54+
}
55+
56+
return 0;
57+
}
58+
EXPORT_SYMBOL(fib_default_rule_pref);
59+
4260
static void notify_rule_change(int event, struct fib_rule *rule,
4361
struct fib_rules_ops *ops, struct nlmsghdr *nlh,
4462
u32 pid);

‎net/decnet/dn_rules.c‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,23 +212,6 @@ static int dn_fib_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
212212
return -ENOBUFS;
213213
}
214214

215-
static u32 dn_fib_rule_default_pref(struct fib_rules_ops *ops)
216-
{
217-
struct list_head *pos;
218-
struct fib_rule *rule;
219-
220-
if (!list_empty(&dn_fib_rules_ops->rules_list)) {
221-
pos = dn_fib_rules_ops->rules_list.next;
222-
if (pos->next != &dn_fib_rules_ops->rules_list) {
223-
rule = list_entry(pos->next, struct fib_rule, list);
224-
if (rule->pref)
225-
return rule->pref - 1;
226-
}
227-
}
228-
229-
return 0;
230-
}
231-
232215
static void dn_fib_rule_flush_cache(struct fib_rules_ops *ops)
233216
{
234217
dn_rt_cache_flush(-1);
@@ -243,7 +226,7 @@ static struct fib_rules_ops dn_fib_rules_ops_template = {
243226
.configure = dn_fib_rule_configure,
244227
.compare = dn_fib_rule_compare,
245228
.fill = dn_fib_rule_fill,
246-
.default_pref = dn_fib_rule_default_pref,
229+
.default_pref = fib_default_rule_pref,
247230
.flush_cache = dn_fib_rule_flush_cache,
248231
.nlgroup = RTNLGRP_DECnet_RULE,
249232
.policy = dn_fib_rule_policy,

‎net/ipv4/fib_rules.c‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,6 @@ static int fib4_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
234234
return -ENOBUFS;
235235
}
236236

237-
static u32 fib4_rule_default_pref(struct fib_rules_ops *ops)
238-
{
239-
struct list_head *pos;
240-
struct fib_rule *rule;
241-
242-
if (!list_empty(&ops->rules_list)) {
243-
pos = ops->rules_list.next;
244-
if (pos->next != &ops->rules_list) {
245-
rule = list_entry(pos->next, struct fib_rule, list);
246-
if (rule->pref)
247-
return rule->pref - 1;
248-
}
249-
}
250-
251-
return 0;
252-
}
253-
254237
static size_t fib4_rule_nlmsg_payload(struct fib_rule *rule)
255238
{
256239
return nla_total_size(4) /* dst */
@@ -272,7 +255,7 @@ static struct fib_rules_ops fib4_rules_ops_template = {
272255
.configure = fib4_rule_configure,
273256
.compare = fib4_rule_compare,
274257
.fill = fib4_rule_fill,
275-
.default_pref = fib4_rule_default_pref,
258+
.default_pref = fib_default_rule_pref,
276259
.nlmsg_payload = fib4_rule_nlmsg_payload,
277260
.flush_cache = fib4_rule_flush_cache,
278261
.nlgroup = RTNLGRP_IPV4_RULE,

0 commit comments

Comments
 (0)