[PATCH 3/5] [NET]: Protocol Independant Policy Routing Rules Framework
Derived from net/ipv/fib_rules.c Signed-off-by: Thomas Graf [EMAIL PROTECTED] Index: net-2.6.19/include/linux/fib_rules.h === --- /dev/null +++ net-2.6.19/include/linux/fib_rules.h @@ -0,0 +1,60 @@ +#ifndef __LINUX_FIB_RULES_H +#define __LINUX_FIB_RULES_H + +#include linux/types.h +#include linux/rtnetlink.h + +/* rule is permanent, and cannot be deleted */ +#define FIB_RULE_PERMANENT 1 + +struct fib_rule_hdr +{ + __u8family; + __u8dst_len; + __u8src_len; + __u8tos; + + __u8table; + __u8res1; /* reserved */ + __u8res2; /* reserved */ + __u8action; + + __u32 flags; +}; + +enum +{ + FRA_UNSPEC, + FRA_DST,/* destination address */ + FRA_SRC,/* source address */ + FRA_IFNAME, /* interface name */ + FRA_UNUSED1, + FRA_UNUSED2, + FRA_PRIORITY, /* priority/preference */ + FRA_UNUSED3, + FRA_UNUSED4, + FRA_UNUSED5, + FRA_FWMARK, /* netfilter mark (IPv4) */ + FRA_FLOW, /* flow/class id */ + __FRA_MAX +}; + +#define FRA_MAX (__FRA_MAX - 1) + +enum +{ + FR_ACT_UNSPEC, + FR_ACT_TO_TBL, /* Pass to fixed table */ + FR_ACT_RES1, + FR_ACT_RES2, + FR_ACT_RES3, + FR_ACT_RES4, + FR_ACT_BLACKHOLE, /* Drop without notification */ + FR_ACT_UNREACHABLE, /* Drop with ENETUNREACH */ + FR_ACT_PROHIBIT,/* Drop with EACCES */ + __FR_ACT_MAX, +}; + +#define FR_ACT_MAX (__FR_ACT_MAX - 1) + +#endif Index: net-2.6.19/include/net/fib_rules.h === --- /dev/null +++ net-2.6.19/include/net/fib_rules.h @@ -0,0 +1,90 @@ +#ifndef __NET_FIB_RULES_H +#define __NET_FIB_RULES_H + +#include linux/types.h +#include linux/netdevice.h +#include linux/fib_rules.h +#include net/flow.h +#include net/netlink.h + +struct fib_rule +{ + struct list_headlist; + atomic_trefcnt; + int ifindex; + charifname[IFNAMSIZ]; + u32 pref; + u32 flags; + u32 table; + u8 action; + struct rcu_head rcu; +}; + +struct fib_lookup_arg +{ + void*lookup_ptr; + void*result; + struct fib_rule *rule; +}; + +struct fib_rules_ops +{ + int family; + struct list_headlist; + int rule_size; + + int (*action)(struct fib_rule *, + struct flowi *, int, + struct fib_lookup_arg *); + int (*match)(struct fib_rule *, +struct flowi *, int); + int (*configure)(struct fib_rule *, +struct sk_buff *, +struct nlmsghdr *, +struct fib_rule_hdr *, +struct nlattr **); + int (*compare)(struct fib_rule *, + struct fib_rule_hdr *, + struct nlattr **); + int (*fill)(struct fib_rule *, struct sk_buff *, + struct nlmsghdr *, + struct fib_rule_hdr *); + u32 (*default_pref)(void); + + int nlgroup; + struct nla_policy *policy; + struct list_head*rules_list; + struct module *owner; +}; + +static inline void fib_rule_get(struct fib_rule *rule) +{ + atomic_inc(rule-refcnt); +} + +static inline void fib_rule_put_rcu(struct rcu_head *head) +{ + struct fib_rule *rule = container_of(head, struct fib_rule, rcu); + kfree(rule); +} + +static inline void fib_rule_put(struct fib_rule *rule) +{ + if (atomic_dec_and_test(rule-refcnt)) + call_rcu(rule-rcu, fib_rule_put_rcu); +} + +extern int fib_rules_register(struct fib_rules_ops *); +extern int fib_rules_unregister(struct fib_rules_ops *); + +extern int fib_rules_lookup(struct fib_rules_ops *, +struct flowi *, int flags, +struct fib_lookup_arg *); + +extern int fib_nl_newrule(struct sk_buff *, + struct nlmsghdr *, void *); +extern int
Re: [PATCH 3/5] [NET]: Protocol Independant Policy Routing Rules Framework
On Thu, 27 Jul 2006, Thomas Graf wrote: + rule = kmalloc(ops-rule_size, GFP_KERNEL); + if (rule == NULL) { + err = -ENOMEM; + goto errout; + } + memset(rule, 0, ops-rule_size); + kzalloc() ? :-) - James -- James Morris [EMAIL PROTECTED] - To unsubscribe from this list: send the line unsubscribe netdev in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/5] [NET]: Protocol Independant Policy Routing Rules Framework
Derived from net/ipv6/fib_rules.c Signed-off-by: Thomas Graf [EMAIL PROTECTED] Index: net-2.6.git/include/linux/fib_rules.h === --- /dev/null +++ net-2.6.git/include/linux/fib_rules.h @@ -0,0 +1,60 @@ +#ifndef __LINUX_FIB_RULES_H +#define __LINUX_FIB_RULES_H + +#include linux/types.h +#include linux/rtnetlink.h + +/* rule is permanent, and cannot be deleted */ +#define FIB_RULE_PERMANENT 1 + +struct fib_rule_hdr +{ + __u8family; + __u8dst_len; + __u8src_len; + __u8tos; + + __u8table; + __u8res1; /* reserved */ + __u8res2; /* reserved */ + __u8action; + + __u32 flags; +}; + +enum +{ + FRA_UNSPEC, + FRA_DST,/* destination address */ + FRA_SRC,/* source address */ + FRA_IFNAME, /* interface name */ + FRA_UNUSED1, + FRA_UNUSED2, + FRA_PRIORITY, /* priority/preference */ + FRA_UNUSED3, + FRA_UNUSED4, + FRA_UNUSED5, + FRA_FWMARK, /* netfilter mark (IPv4) */ + FRA_FLOW, /* flow/class id */ + __FRA_MAX +}; + +#define FRA_MAX (__FRA_MAX - 1) + +enum +{ + FR_ACT_UNSPEC, + FR_ACT_TO_TBL, /* Pass to fixed table */ + FR_ACT_RES1, + FR_ACT_RES2, + FR_ACT_RES3, + FR_ACT_RES4, + FR_ACT_BLACKHOLE, /* Drop without notification */ + FR_ACT_UNREACHABLE, /* Drop with ENETUNREACH */ + FR_ACT_PROHIBIT,/* Drop with EACCES */ + __FR_ACT_MAX, +}; + +#define FR_ACT_MAX (__FR_ACT_MAX - 1) + +#endif Index: net-2.6.git/include/net/fib_rules.h === --- /dev/null +++ net-2.6.git/include/net/fib_rules.h @@ -0,0 +1,89 @@ +#ifndef __NET_FIB_RULES_H +#define __NET_FIB_RULES_H + +#include linux/types.h +#include linux/netdevice.h +#include linux/fib_rules.h +#include net/flow.h +#include net/netlink.h + +struct fib_rule +{ + struct list_headlist; + atomic_trefcnt; + int ifindex; + charifname[IFNAMSIZ]; + u32 pref; + u32 flags; + u32 table; + u8 action; + struct rcu_head rcu; +}; + +struct fib_lookup_arg +{ + void*lookup_ptr; + void*result; + struct fib_rule *rule; +}; + +struct fib_rules_ops +{ + int family; + struct list_headlist; + int rule_size; + + int (*action)(struct fib_rule *, + struct flowi *, int, + struct fib_lookup_arg *); + int (*match)(struct fib_rule *, +struct flowi *, int); + int (*configure)(struct fib_rule *, +struct sk_buff *, +struct nlmsghdr *, +struct fib_rule_hdr *, +struct nlattr **); + int (*compare)(struct fib_rule *, + struct fib_rule_hdr *, + struct nlattr **); + int (*fill)(struct fib_rule *, struct sk_buff *, + struct nlmsghdr *, + struct fib_rule_hdr *); + u32 (*default_pref)(void); + + struct nla_policy *policy; + struct list_head*rules_list; + struct module *owner; +}; + +static inline void fib_rule_get(struct fib_rule *rule) +{ + atomic_inc(rule-refcnt); +} + +static inline void fib_rule_put_rcu(struct rcu_head *head) +{ + struct fib_rule *rule = container_of(head, struct fib_rule, rcu); + kfree(rule); +} + +static inline void fib_rule_put(struct fib_rule *rule) +{ + if (atomic_dec_and_test(rule-refcnt)) + call_rcu(rule-rcu, fib_rule_put_rcu); +} + +extern int fib_rules_register(struct fib_rules_ops *); +extern int fib_rules_unregister(struct fib_rules_ops *); + +extern int fib_rules_lookup(struct fib_rules_ops *, +struct flowi *, int flags, +struct fib_lookup_arg *); + +extern int fib_nl_newrule(struct sk_buff *, + struct nlmsghdr *, void *); +extern int fib_nl_delrule(struct
Re: [PATCH 3/5] [NET]: Protocol Independant Policy Routing Rules Framework
From: Thomas Graf [EMAIL PROTECTED] Date: Thu, 27 Jul 2006 00:00:03 +0200 Derived from net/ipv6/fib_rules.c Signed-off-by: Thomas Graf [EMAIL PROTECTED] A very nice abstraction, looks great. Signed-off-by: David S. Miller [EMAIL PROTECTED] - To unsubscribe from this list: send the line unsubscribe netdev in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html