at v2.6.21 108 lines 2.6 kB view raw
1#ifndef __NET_FIB_RULES_H 2#define __NET_FIB_RULES_H 3 4#include <linux/types.h> 5#include <linux/netdevice.h> 6#include <linux/fib_rules.h> 7#include <net/flow.h> 8#include <net/netlink.h> 9 10struct fib_rule 11{ 12 struct list_head list; 13 atomic_t refcnt; 14 int ifindex; 15 char ifname[IFNAMSIZ]; 16 u32 mark; 17 u32 mark_mask; 18 u32 pref; 19 u32 flags; 20 u32 table; 21 u8 action; 22 struct rcu_head rcu; 23}; 24 25struct fib_lookup_arg 26{ 27 void *lookup_ptr; 28 void *result; 29 struct fib_rule *rule; 30}; 31 32struct fib_rules_ops 33{ 34 int family; 35 struct list_head list; 36 int rule_size; 37 int addr_size; 38 39 int (*action)(struct fib_rule *, 40 struct flowi *, int, 41 struct fib_lookup_arg *); 42 int (*match)(struct fib_rule *, 43 struct flowi *, int); 44 int (*configure)(struct fib_rule *, 45 struct sk_buff *, 46 struct nlmsghdr *, 47 struct fib_rule_hdr *, 48 struct nlattr **); 49 int (*compare)(struct fib_rule *, 50 struct fib_rule_hdr *, 51 struct nlattr **); 52 int (*fill)(struct fib_rule *, struct sk_buff *, 53 struct nlmsghdr *, 54 struct fib_rule_hdr *); 55 u32 (*default_pref)(void); 56 size_t (*nlmsg_payload)(struct fib_rule *); 57 58 int nlgroup; 59 struct nla_policy *policy; 60 struct list_head *rules_list; 61 struct module *owner; 62}; 63 64#define FRA_GENERIC_POLICY \ 65 [FRA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ 66 [FRA_PRIORITY] = { .type = NLA_U32 }, \ 67 [FRA_FWMARK] = { .type = NLA_U32 }, \ 68 [FRA_FWMASK] = { .type = NLA_U32 }, \ 69 [FRA_TABLE] = { .type = NLA_U32 } 70 71static inline void fib_rule_get(struct fib_rule *rule) 72{ 73 atomic_inc(&rule->refcnt); 74} 75 76static inline void fib_rule_put_rcu(struct rcu_head *head) 77{ 78 struct fib_rule *rule = container_of(head, struct fib_rule, rcu); 79 kfree(rule); 80} 81 82static inline void fib_rule_put(struct fib_rule *rule) 83{ 84 if (atomic_dec_and_test(&rule->refcnt)) 85 call_rcu(&rule->rcu, fib_rule_put_rcu); 86} 87 88static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla) 89{ 90 if (nla[FRA_TABLE]) 91 return nla_get_u32(nla[FRA_TABLE]); 92 return frh->table; 93} 94 95extern int fib_rules_register(struct fib_rules_ops *); 96extern int fib_rules_unregister(struct fib_rules_ops *); 97 98extern int fib_rules_lookup(struct fib_rules_ops *, 99 struct flowi *, int flags, 100 struct fib_lookup_arg *); 101 102extern int fib_nl_newrule(struct sk_buff *, 103 struct nlmsghdr *, void *); 104extern int fib_nl_delrule(struct sk_buff *, 105 struct nlmsghdr *, void *); 106extern int fib_rules_dump(struct sk_buff *, 107 struct netlink_callback *, int); 108#endif