root/include/net/ip_masq.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  *      IP masquerading functionality definitions
   3  */
   4 
   5 #ifndef _IP_MASQ_H
   6 #define _IP_MASQ_H
   7 
   8 #include <linux/types.h>
   9 #include <linux/netdevice.h>
  10 #include <linux/skbuff.h>
  11 
  12 /*
  13  *      Linux ports don't normally get allocated above 32K.
  14  *      I used an extra 4K port-space
  15  */
  16  
  17 #define PORT_MASQ_BEGIN 60000
  18 #define PORT_MASQ_END   (PORT_MASQ_BEGIN+4096)
  19 
  20 #define MASQUERADE_EXPIRE_TCP     15*60*HZ
  21 #define MASQUERADE_EXPIRE_TCP_FIN  2*60*HZ
  22 #define MASQUERADE_EXPIRE_UDP      5*60*HZ
  23 
  24 #define IP_MASQ_F_OUT_SEQ               0x01    /* must do output seq adjust */
  25 #define IP_MASQ_F_IN_SEQ                0x02    /* must do input seq adjust */
  26 #define IP_MASQ_F_NO_DPORT              0x04    /* no dport set yet */
  27 #define IP_MASQ_F_NO_DADDR              0x08    /* no daddr yet */
  28 #define IP_MASQ_F_HASHED                0x10    /* hashed entry */
  29 #define IP_MASQ_F_SAW_FIN               0x20    /* tcp fin pkt seen */
  30 #define IP_MASQ_F_SAW_RST               0x40    /* tcp rst pkt seen */
  31 
  32 #ifdef __KERNEL__
  33 
  34 /*
  35  *      Delta seq. info structure
  36  *      Each MASQ struct has 2 (output AND input seq. changes).
  37  */
  38 
  39 struct ip_masq_seq {
  40         __u32           init_seq;       /* Add delta from this seq */
  41         short           delta;          /* Delta in sequence numbers */
  42         short           previous_delta; /* Delta in sequence numbers before last resized pkt */
  43 };
  44 
  45 /*
  46  *      MASQ structure allocated for each masqueraded association
  47  */
  48 struct ip_masq {
  49         struct ip_masq  *m_link, *s_link; /* hashed link ptrs */
  50         struct timer_list timer;        /* Expiration timer */
  51         __u16           protocol;       /* Which protocol are we talking? */
  52         __u16           sport, dport, mport;    /* src, dst & masq ports */
  53         __u32           saddr, daddr, maddr;    /* src, dst & masq addresses */
  54         struct ip_masq_seq out_seq, in_seq;
  55         struct ip_masq_app *app;        /* bound ip_masq_app object */
  56         void            *app_data;      /* Application private data */
  57         unsigned  flags;                /* status flags */
  58 };
  59 
  60 /*
  61  *      timeout values
  62  */
  63 
  64 struct ip_fw_masq {
  65         int tcp_timeout;
  66         int tcp_fin_timeout;
  67         int udp_timeout;
  68 };
  69 
  70 extern struct ip_fw_masq *ip_masq_expire;
  71 
  72 /*
  73  *      [0]: UDP free_ports
  74  *      [1]: TCP free_ports
  75  */
  76 
  77 extern int ip_masq_free_ports[2];
  78 
  79 /*
  80  *      ip_masq initializer (registers symbols and /proc/net entries)
  81  */
  82 extern int ip_masq_init(void);
  83 
  84 /*
  85  *      functions called from ip layer
  86  */
  87 extern void ip_fw_masquerade(struct sk_buff **, struct device *);
  88 extern int ip_fw_demasquerade(struct sk_buff **, struct device *);
  89 
  90 /*
  91  *      ip_masq obj creation/deletion functions.
  92  */
  93 extern struct ip_masq *ip_masq_new(struct device *dev, int proto, __u32 saddr, __u16 sport, __u32 daddr, __u16 dport, unsigned flags);
  94 extern void ip_masq_set_expire(struct ip_masq *ms, unsigned long tout);
  95 
  96 
  97 /*
  98  *      
  99  *      IP_MASQ_APP: IP application masquerading definitions 
 100  *
 101  */
 102 
 103 struct ip_masq_app
 104 {
 105         struct ip_masq_app *next;
 106         char *name;             /* name of application proxy */
 107         unsigned type;          /* type = proto<<16 | port (host byte order)*/
 108         int n_attach;
 109         int (*masq_init_1)      /* ip_masq initializer */
 110                 (struct ip_masq_app *, struct ip_masq *);
 111         int (*masq_done_1)      /* ip_masq fin. */
 112                 (struct ip_masq_app *, struct ip_masq *);
 113         int (*pkt_out)          /* output (masquerading) hook */
 114                 (struct ip_masq_app *, struct ip_masq *, struct sk_buff **, struct device *);
 115         int (*pkt_in)           /* input (demasq) hook */
 116                 (struct ip_masq_app *, struct ip_masq *, struct sk_buff **, struct device *);
 117 };
 118 
 119 /*
 120  *      ip_masq_app initializer
 121  */
 122 extern int ip_masq_app_init(void);
 123 
 124 /*
 125  *      ip_masq_app object registration functions (port: host byte order)
 126  */
 127 extern int register_ip_masq_app(struct ip_masq_app *mapp, unsigned short proto, __u16 port);
 128 extern int unregister_ip_masq_app(struct ip_masq_app *mapp);
 129 
 130 /*
 131  *      get ip_masq_app obj by proto,port(net_byte_order)
 132  */
 133 extern struct ip_masq_app * ip_masq_app_get(unsigned short proto, __u16 port);
 134 
 135 /*
 136  *      ip_masq TO ip_masq_app (un)binding functions.
 137  */
 138 extern struct ip_masq_app * ip_masq_bind_app(struct ip_masq *ms);
 139 extern int ip_masq_unbind_app(struct ip_masq *ms);
 140 
 141 /*
 142  *      output and input app. masquerading hooks.
 143  *      
 144  */
 145 extern int ip_masq_app_pkt_out(struct ip_masq *, struct sk_buff **skb_p, struct device *dev);
 146 extern int ip_masq_app_pkt_in(struct ip_masq *, struct sk_buff **skb_p, struct device *dev);
 147 
 148 /*
 149  *      service routine(s).
 150  */
 151 extern struct ip_masq * ip_masq_out_get_2(int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
 152 
 153 /*
 154  *      /proc/net entry
 155  */
 156 extern int ip_masq_app_getinfo(char *buffer, char **start, off_t offset, int length, int dummy);
 157 
 158 /*
 159  *      skb_replace function used by "client" modules to replace
 160  *      a segment of skb.
 161  */
 162 extern struct sk_buff * ip_masq_skb_replace(struct sk_buff *skb, int pri, char *o_buf, int o_len, char *n_buf, int n_len);
 163 
 164 #endif /* __KERNEL__ */
 165 
 166 #endif /* _IP_MASQ_H */

/* [previous][next][first][last][top][bottom][index][help] */