Lines Matching refs:rule

38 bool fib_rule_matchall(const struct fib_rule *rule)  in fib_rule_matchall()  argument
40 if (rule->iifindex || rule->oifindex || rule->mark || rule->tun_id || in fib_rule_matchall()
41 rule->flags) in fib_rule_matchall()
43 if (rule->suppress_ifgroup != -1 || rule->suppress_prefixlen != -1) in fib_rule_matchall()
45 if (!uid_eq(rule->uid_range.start, fib_kuid_range_unset.start) || in fib_rule_matchall()
46 !uid_eq(rule->uid_range.end, fib_kuid_range_unset.end)) in fib_rule_matchall()
48 if (fib_rule_port_range_set(&rule->sport_range)) in fib_rule_matchall()
50 if (fib_rule_port_range_set(&rule->dport_range)) in fib_rule_matchall()
86 struct fib_rule *rule; in fib_default_rule_pref() local
91 rule = list_entry(pos->next, struct fib_rule, list); in fib_default_rule_pref()
92 if (rule->pref) in fib_default_rule_pref()
93 return rule->pref - 1; in fib_default_rule_pref()
100 static void notify_rule_change(int event, struct fib_rule *rule,
189 struct fib_rule *rule, *tmp; in fib_rules_cleanup_ops() local
191 list_for_each_entry_safe(rule, tmp, &ops->rules_list, list) { in fib_rules_cleanup_ops()
192 list_del_rcu(&rule->list); in fib_rules_cleanup_ops()
194 ops->delete(rule); in fib_rules_cleanup_ops()
195 fib_rule_put(rule); in fib_rules_cleanup_ops()
260 static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops, in fib_rule_match() argument
266 if (rule->iifindex && (rule->iifindex != fl->flowi_iif)) in fib_rule_match()
269 if (rule->oifindex && (rule->oifindex != fl->flowi_oif)) in fib_rule_match()
272 if ((rule->mark ^ fl->flowi_mark) & rule->mark_mask) in fib_rule_match()
275 if (rule->tun_id && (rule->tun_id != fl->flowi_tun_key.tun_id)) in fib_rule_match()
278 if (rule->l3mdev && !l3mdev_fib_rule_match(rule->fr_net, fl, arg)) in fib_rule_match()
281 if (uid_lt(fl->flowi_uid, rule->uid_range.start) || in fib_rule_match()
282 uid_gt(fl->flowi_uid, rule->uid_range.end)) in fib_rule_match()
288 rule, fl, flags); in fib_rule_match()
290 return (rule->flags & FIB_RULE_INVERT) ? !ret : ret; in fib_rule_match()
296 struct fib_rule *rule; in fib_rules_lookup() local
301 list_for_each_entry_rcu(rule, &ops->rules_list, list) { in fib_rules_lookup()
303 if (!fib_rule_match(rule, ops, fl, flags, arg)) in fib_rules_lookup()
306 if (rule->action == FR_ACT_GOTO) { in fib_rules_lookup()
309 target = rcu_dereference(rule->ctarget); in fib_rules_lookup()
313 rule = target; in fib_rules_lookup()
316 } else if (rule->action == FR_ACT_NOP) in fib_rules_lookup()
322 rule, fl, flags, arg); in fib_rules_lookup()
327 rule, flags, arg)) in fib_rules_lookup()
332 likely(refcount_inc_not_zero(&rule->refcnt))) { in fib_rules_lookup()
333 arg->rule = rule; in fib_rules_lookup()
350 struct fib_rule *rule, int family, in call_fib_rule_notifier() argument
356 .rule = rule, in call_fib_rule_notifier()
364 struct fib_rule *rule, in call_fib_rule_notifiers() argument
371 .rule = rule, in call_fib_rule_notifiers()
385 struct fib_rule *rule; in fib_rules_dump() local
391 list_for_each_entry_rcu(rule, &ops->rules_list, list) { in fib_rules_dump()
393 rule, family, extack); in fib_rules_dump()
422 struct fib_rule *rule, in rule_find()
428 if (rule->action && r->action != rule->action) in rule_find()
431 if (rule->table && r->table != rule->table) in rule_find()
434 if (user_priority && r->pref != rule->pref) in rule_find()
437 if (rule->iifname[0] && in rule_find()
438 memcmp(r->iifname, rule->iifname, IFNAMSIZ)) in rule_find()
441 if (rule->oifname[0] && in rule_find()
442 memcmp(r->oifname, rule->oifname, IFNAMSIZ)) in rule_find()
445 if (rule->mark && r->mark != rule->mark) in rule_find()
448 if (rule->suppress_ifgroup != -1 && in rule_find()
449 r->suppress_ifgroup != rule->suppress_ifgroup) in rule_find()
452 if (rule->suppress_prefixlen != -1 && in rule_find()
453 r->suppress_prefixlen != rule->suppress_prefixlen) in rule_find()
456 if (rule->mark_mask && r->mark_mask != rule->mark_mask) in rule_find()
459 if (rule->tun_id && r->tun_id != rule->tun_id) in rule_find()
462 if (r->fr_net != rule->fr_net) in rule_find()
465 if (rule->l3mdev && r->l3mdev != rule->l3mdev) in rule_find()
468 if (uid_range_set(&rule->uid_range) && in rule_find()
469 (!uid_eq(r->uid_range.start, rule->uid_range.start) || in rule_find()
470 !uid_eq(r->uid_range.end, rule->uid_range.end))) in rule_find()
473 if (rule->ip_proto && r->ip_proto != rule->ip_proto) in rule_find()
476 if (rule->proto && r->proto != rule->proto) in rule_find()
479 if (fib_rule_port_range_set(&rule->sport_range) && in rule_find()
481 &rule->sport_range)) in rule_find()
484 if (fib_rule_port_range_set(&rule->dport_range) && in rule_find()
486 &rule->dport_range)) in rule_find()
522 struct fib_rule **rule, in fib_nl2rule() argument
676 *rule = nlrule; in fib_nl2rule()
687 struct nlattr **tb, struct fib_rule *rule) in rule_exists() argument
692 if (r->action != rule->action) in rule_exists()
695 if (r->table != rule->table) in rule_exists()
698 if (r->pref != rule->pref) in rule_exists()
701 if (memcmp(r->iifname, rule->iifname, IFNAMSIZ)) in rule_exists()
704 if (memcmp(r->oifname, rule->oifname, IFNAMSIZ)) in rule_exists()
707 if (r->mark != rule->mark) in rule_exists()
710 if (r->suppress_ifgroup != rule->suppress_ifgroup) in rule_exists()
713 if (r->suppress_prefixlen != rule->suppress_prefixlen) in rule_exists()
716 if (r->mark_mask != rule->mark_mask) in rule_exists()
719 if (r->tun_id != rule->tun_id) in rule_exists()
722 if (r->fr_net != rule->fr_net) in rule_exists()
725 if (r->l3mdev != rule->l3mdev) in rule_exists()
728 if (!uid_eq(r->uid_range.start, rule->uid_range.start) || in rule_exists()
729 !uid_eq(r->uid_range.end, rule->uid_range.end)) in rule_exists()
732 if (r->ip_proto != rule->ip_proto) in rule_exists()
735 if (r->proto != rule->proto) in rule_exists()
739 &rule->sport_range)) in rule_exists()
743 &rule->dport_range)) in rule_exists()
781 struct fib_rule *rule = NULL, *r, *last = NULL; in fib_nl_newrule() local
805 err = fib_nl2rule(skb, nlh, extack, ops, tb, &rule, &user_priority); in fib_nl_newrule()
810 rule_exists(ops, frh, tb, rule)) { in fib_nl_newrule()
815 err = ops->configure(rule, skb, frh, tb, extack); in fib_nl_newrule()
819 err = call_fib_rule_notifiers(net, FIB_EVENT_RULE_ADD, rule, ops, in fib_nl_newrule()
825 if (r->pref == rule->target) { in fib_nl_newrule()
826 RCU_INIT_POINTER(rule->ctarget, r); in fib_nl_newrule()
831 if (rcu_dereference_protected(rule->ctarget, 1) == NULL) in fib_nl_newrule()
835 if (r->pref > rule->pref) in fib_nl_newrule()
841 list_add_rcu(&rule->list, &last->list); in fib_nl_newrule()
843 list_add_rcu(&rule->list, &ops->rules_list); in fib_nl_newrule()
852 r->target == rule->pref && in fib_nl_newrule()
854 rcu_assign_pointer(r->ctarget, rule); in fib_nl_newrule()
861 if (rule->action == FR_ACT_GOTO) in fib_nl_newrule()
867 if (rule->tun_id) in fib_nl_newrule()
870 notify_rule_change(RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).portid); in fib_nl_newrule()
876 kfree(rule); in fib_nl_newrule()
889 struct fib_rule *rule = NULL, *r, *nlrule = NULL; in fib_nl_delrule() local
917 rule = rule_find(ops, frh, tb, nlrule, user_priority); in fib_nl_delrule()
918 if (!rule) { in fib_nl_delrule()
923 if (rule->flags & FIB_RULE_PERMANENT) { in fib_nl_delrule()
929 err = ops->delete(rule); in fib_nl_delrule()
934 if (rule->tun_id) in fib_nl_delrule()
937 list_del_rcu(&rule->list); in fib_nl_delrule()
939 if (rule->action == FR_ACT_GOTO) { in fib_nl_delrule()
941 if (rtnl_dereference(rule->ctarget) == NULL) in fib_nl_delrule()
955 n = list_next_entry(rule, list); in fib_nl_delrule()
956 if (&n->list == &ops->rules_list || n->pref != rule->pref) in fib_nl_delrule()
959 if (rtnl_dereference(r->ctarget) != rule) in fib_nl_delrule()
967 call_fib_rule_notifiers(net, FIB_EVENT_RULE_DEL, rule, ops, in fib_nl_delrule()
969 notify_rule_change(RTM_DELRULE, rule, ops, nlh, in fib_nl_delrule()
971 fib_rule_put(rule); in fib_nl_delrule()
985 struct fib_rule *rule) in fib_rule_nlmsg_size() argument
1004 payload += ops->nlmsg_payload(rule); in fib_rule_nlmsg_size()
1009 static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule, in fib_nl_fill_rule() argument
1022 frh->table = rule->table < 256 ? rule->table : RT_TABLE_COMPAT; in fib_nl_fill_rule()
1023 if (nla_put_u32(skb, FRA_TABLE, rule->table)) in fib_nl_fill_rule()
1025 if (nla_put_u32(skb, FRA_SUPPRESS_PREFIXLEN, rule->suppress_prefixlen)) in fib_nl_fill_rule()
1029 frh->action = rule->action; in fib_nl_fill_rule()
1030 frh->flags = rule->flags; in fib_nl_fill_rule()
1032 if (nla_put_u8(skb, FRA_PROTOCOL, rule->proto)) in fib_nl_fill_rule()
1035 if (rule->action == FR_ACT_GOTO && in fib_nl_fill_rule()
1036 rcu_access_pointer(rule->ctarget) == NULL) in fib_nl_fill_rule()
1039 if (rule->iifname[0]) { in fib_nl_fill_rule()
1040 if (nla_put_string(skb, FRA_IIFNAME, rule->iifname)) in fib_nl_fill_rule()
1042 if (rule->iifindex == -1) in fib_nl_fill_rule()
1046 if (rule->oifname[0]) { in fib_nl_fill_rule()
1047 if (nla_put_string(skb, FRA_OIFNAME, rule->oifname)) in fib_nl_fill_rule()
1049 if (rule->oifindex == -1) in fib_nl_fill_rule()
1053 if ((rule->pref && in fib_nl_fill_rule()
1054 nla_put_u32(skb, FRA_PRIORITY, rule->pref)) || in fib_nl_fill_rule()
1055 (rule->mark && in fib_nl_fill_rule()
1056 nla_put_u32(skb, FRA_FWMARK, rule->mark)) || in fib_nl_fill_rule()
1057 ((rule->mark_mask || rule->mark) && in fib_nl_fill_rule()
1058 nla_put_u32(skb, FRA_FWMASK, rule->mark_mask)) || in fib_nl_fill_rule()
1059 (rule->target && in fib_nl_fill_rule()
1060 nla_put_u32(skb, FRA_GOTO, rule->target)) || in fib_nl_fill_rule()
1061 (rule->tun_id && in fib_nl_fill_rule()
1062 nla_put_be64(skb, FRA_TUN_ID, rule->tun_id, FRA_PAD)) || in fib_nl_fill_rule()
1063 (rule->l3mdev && in fib_nl_fill_rule()
1064 nla_put_u8(skb, FRA_L3MDEV, rule->l3mdev)) || in fib_nl_fill_rule()
1065 (uid_range_set(&rule->uid_range) && in fib_nl_fill_rule()
1066 nla_put_uid_range(skb, &rule->uid_range)) || in fib_nl_fill_rule()
1067 (fib_rule_port_range_set(&rule->sport_range) && in fib_nl_fill_rule()
1068 nla_put_port_range(skb, FRA_SPORT_RANGE, &rule->sport_range)) || in fib_nl_fill_rule()
1069 (fib_rule_port_range_set(&rule->dport_range) && in fib_nl_fill_rule()
1070 nla_put_port_range(skb, FRA_DPORT_RANGE, &rule->dport_range)) || in fib_nl_fill_rule()
1071 (rule->ip_proto && nla_put_u8(skb, FRA_IP_PROTO, rule->ip_proto))) in fib_nl_fill_rule()
1074 if (rule->suppress_ifgroup != -1) { in fib_nl_fill_rule()
1075 if (nla_put_u32(skb, FRA_SUPPRESS_IFGROUP, rule->suppress_ifgroup)) in fib_nl_fill_rule()
1079 if (ops->fill(rule, skb, frh) < 0) in fib_nl_fill_rule()
1094 struct fib_rule *rule; in dump_rules() local
1098 list_for_each_entry_rcu(rule, &ops->rules_list, list) { in dump_rules()
1102 err = fib_nl_fill_rule(skb, rule, NETLINK_CB(cb->skb).portid, in dump_rules()
1187 static void notify_rule_change(int event, struct fib_rule *rule, in notify_rule_change() argument
1196 skb = nlmsg_new(fib_rule_nlmsg_size(ops, rule), GFP_KERNEL); in notify_rule_change()
1200 err = fib_nl_fill_rule(skb, rule, pid, nlh->nlmsg_seq, event, 0, ops); in notify_rule_change()
1216 struct fib_rule *rule; in attach_rules() local
1218 list_for_each_entry(rule, rules, list) { in attach_rules()
1219 if (rule->iifindex == -1 && in attach_rules()
1220 strcmp(dev->name, rule->iifname) == 0) in attach_rules()
1221 rule->iifindex = dev->ifindex; in attach_rules()
1222 if (rule->oifindex == -1 && in attach_rules()
1223 strcmp(dev->name, rule->oifname) == 0) in attach_rules()
1224 rule->oifindex = dev->ifindex; in attach_rules()
1230 struct fib_rule *rule; in detach_rules() local
1232 list_for_each_entry(rule, rules, list) { in detach_rules()
1233 if (rule->iifindex == dev->ifindex) in detach_rules()
1234 rule->iifindex = -1; in detach_rules()
1235 if (rule->oifindex == dev->ifindex) in detach_rules()
1236 rule->oifindex = -1; in detach_rules()