11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * 31da177e4SLinus Torvalds * Generic internet FLOW. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds #ifndef _NET_FLOW_H 81da177e4SLinus Torvalds #define _NET_FLOW_H 91da177e4SLinus Torvalds 101da177e4SLinus Torvalds #include <linux/in6.h> 111da177e4SLinus Torvalds #include <asm/atomic.h> 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds struct flowi { 141da177e4SLinus Torvalds int oif; 151da177e4SLinus Torvalds int iif; 1647dcf0cbSThomas Graf __u32 mark; 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds union { 191da177e4SLinus Torvalds struct { 20f2c3fe24SAl Viro __be32 daddr; 21f2c3fe24SAl Viro __be32 saddr; 221da177e4SLinus Torvalds __u8 tos; 231da177e4SLinus Torvalds __u8 scope; 241da177e4SLinus Torvalds } ip4_u; 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds struct { 271da177e4SLinus Torvalds struct in6_addr daddr; 281da177e4SLinus Torvalds struct in6_addr saddr; 2990bcaf7bSAl Viro __be32 flowlabel; 301da177e4SLinus Torvalds } ip6_u; 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds struct { 33c4ea94abSSteven Whitehouse __le16 daddr; 34c4ea94abSSteven Whitehouse __le16 saddr; 351da177e4SLinus Torvalds __u8 scope; 361da177e4SLinus Torvalds } dn_u; 371da177e4SLinus Torvalds } nl_u; 381da177e4SLinus Torvalds #define fld_dst nl_u.dn_u.daddr 391da177e4SLinus Torvalds #define fld_src nl_u.dn_u.saddr 401da177e4SLinus Torvalds #define fld_scope nl_u.dn_u.scope 411da177e4SLinus Torvalds #define fl6_dst nl_u.ip6_u.daddr 421da177e4SLinus Torvalds #define fl6_src nl_u.ip6_u.saddr 431da177e4SLinus Torvalds #define fl6_flowlabel nl_u.ip6_u.flowlabel 441da177e4SLinus Torvalds #define fl4_dst nl_u.ip4_u.daddr 451da177e4SLinus Torvalds #define fl4_src nl_u.ip4_u.saddr 461da177e4SLinus Torvalds #define fl4_tos nl_u.ip4_u.tos 471da177e4SLinus Torvalds #define fl4_scope nl_u.ip4_u.scope 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds __u8 proto; 50a210d01aSJulian Anastasov __u8 flags; 51a210d01aSJulian Anastasov #define FLOWI_FLAG_ANYSRC 0x01 524465b469STom Herbert #define FLOWI_FLAG_MATCH_ANY_IIF 0x02 531da177e4SLinus Torvalds union { 541da177e4SLinus Torvalds struct { 55cc939d37SAl Viro __be16 sport; 56cc939d37SAl Viro __be16 dport; 571da177e4SLinus Torvalds } ports; 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds struct { 601da177e4SLinus Torvalds __u8 type; 611da177e4SLinus Torvalds __u8 code; 621da177e4SLinus Torvalds } icmpt; 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds struct { 65c4ea94abSSteven Whitehouse __le16 sport; 66c4ea94abSSteven Whitehouse __le16 dport; 671da177e4SLinus Torvalds } dnports; 681da177e4SLinus Torvalds 694324a174SAl Viro __be32 spi; 702b741653SMasahide NAKAMURA 712b741653SMasahide NAKAMURA struct { 722b741653SMasahide NAKAMURA __u8 type; 732b741653SMasahide NAKAMURA } mht; 741da177e4SLinus Torvalds } uli_u; 751da177e4SLinus Torvalds #define fl_ip_sport uli_u.ports.sport 761da177e4SLinus Torvalds #define fl_ip_dport uli_u.ports.dport 771da177e4SLinus Torvalds #define fl_icmp_type uli_u.icmpt.type 781da177e4SLinus Torvalds #define fl_icmp_code uli_u.icmpt.code 791da177e4SLinus Torvalds #define fl_ipsec_spi uli_u.spi 802b741653SMasahide NAKAMURA #define fl_mh_type uli_u.mht.type 81b6340fcdSVenkat Yekkirala __u32 secid; /* used by xfrm; see secid.txt */ 821da177e4SLinus Torvalds } __attribute__((__aligned__(BITS_PER_LONG/8))); 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds #define FLOW_DIR_IN 0 851da177e4SLinus Torvalds #define FLOW_DIR_OUT 1 861da177e4SLinus Torvalds #define FLOW_DIR_FWD 2 871da177e4SLinus Torvalds 8852479b62SAlexey Dobriyan struct net; 89df71837dSTrent Jaeger struct sock; 90fe1a5f03STimo Teräs struct flow_cache_ops; 911da177e4SLinus Torvalds 92fe1a5f03STimo Teräs struct flow_cache_object { 93fe1a5f03STimo Teräs const struct flow_cache_ops *ops; 94fe1a5f03STimo Teräs }; 95fe1a5f03STimo Teräs 96fe1a5f03STimo Teräs struct flow_cache_ops { 97fe1a5f03STimo Teräs struct flow_cache_object *(*get)(struct flow_cache_object *); 98fe1a5f03STimo Teräs int (*check)(struct flow_cache_object *); 99fe1a5f03STimo Teräs void (*delete)(struct flow_cache_object *); 100fe1a5f03STimo Teräs }; 101fe1a5f03STimo Teräs 102fe1a5f03STimo Teräs typedef struct flow_cache_object *(*flow_resolve_t)( 103fe1a5f03STimo Teräs struct net *net, struct flowi *key, u16 family, 104fe1a5f03STimo Teräs u8 dir, struct flow_cache_object *oldobj, void *ctx); 105fe1a5f03STimo Teräs 106fe1a5f03STimo Teräs extern struct flow_cache_object *flow_cache_lookup( 107fe1a5f03STimo Teräs struct net *net, struct flowi *key, u16 family, 108fe1a5f03STimo Teräs u8 dir, flow_resolve_t resolver, void *ctx); 109fe1a5f03STimo Teräs 1101da177e4SLinus Torvalds extern void flow_cache_flush(void); 1111da177e4SLinus Torvalds extern atomic_t flow_cache_genid; 1121da177e4SLinus Torvalds 113157bfc25SMasahide NAKAMURA static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2) 114157bfc25SMasahide NAKAMURA { 115157bfc25SMasahide NAKAMURA return (fl1->proto == fl2->proto && 116157bfc25SMasahide NAKAMURA !memcmp(&fl1->uli_u, &fl2->uli_u, sizeof(fl1->uli_u))); 117157bfc25SMasahide NAKAMURA } 118157bfc25SMasahide NAKAMURA 1191da177e4SLinus Torvalds #endif 120