root/include/linux/ip_fw.h

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

INCLUDED FROM


   1 /*
   2  *      IP firewalling code. This is taken from 4.4BSD. Please note the 
   3  *      copyright message below. As per the GPL it must be maintained
   4  *      and the licenses thus do not conflict. While this port is subject
   5  *      to the GPL I also place my modifications under the original 
   6  *      license in recognition of the original copyright. 
   7  *
   8  *      Ported from BSD to Linux,
   9  *              Alan Cox 22/Nov/1994.
  10  *      Merged and included the FreeBSD-Current changes at Ugen's request
  11  *      (but hey it's a lot cleaner now). Ugen would prefer in some ways
  12  *      we waited for his final product but since Linux 1.2.0 is about to
  13  *      appear it's not practical - Read: It works, it's not clean but please
  14  *      don't consider it to be his standard of finished work.
  15  *              Alan.
  16  *
  17  * Fixes:
  18  *      Pauline Middelink       :       Added masquerading.
  19  *      Jos Vos                 :       Separate input  and output firewall
  20  *                                      chains, new "insert" and "append"
  21  *                                      commands to replace "add" commands,
  22  *                                      add ICMP header to struct ip_fwpkt.
  23  *      Jos Vos                 :       Add support for matching device names.
  24  *
  25  *      All the real work was done by .....
  26  */
  27 
  28 /*
  29  * Copyright (c) 1993 Daniel Boulet
  30  * Copyright (c) 1994 Ugen J.S.Antsilevich
  31  *
  32  * Redistribution and use in source forms, with and without modification,
  33  * are permitted provided that this entire comment appears intact.
  34  *
  35  * Redistribution in binary form may occur without any restrictions.
  36  * Obviously, it would be nice if you gave credit where credit is due
  37  * but requiring it would be too onerous.
  38  *
  39  * This software is provided ``AS IS'' without any warranties of any kind.
  40  */
  41 
  42 /*
  43  *      Format of an IP firewall descriptor
  44  *
  45  *      src, dst, src_mask, dst_mask are always stored in network byte order.
  46  *      flags and num_*_ports are stored in host byte order (of course).
  47  *      Port numbers are stored in HOST byte order.
  48  */
  49  
  50 #ifndef _IP_FW_H
  51 #define _IP_FW_H
  52 
  53 struct ip_fw 
  54 {
  55         struct ip_fw  *fw_next;                 /* Next firewall on chain */
  56         struct in_addr fw_src, fw_dst;          /* Source and destination IP addr */
  57         struct in_addr fw_smsk, fw_dmsk;        /* Mask for src and dest IP addr */
  58         struct in_addr fw_via;                  /* IP address of interface "via" */
  59         struct device *fw_viadev;               /* device of interface "via" */
  60         unsigned short fw_flg;                  /* Flags word */
  61         unsigned short fw_nsp, fw_ndp;          /* N'of src ports and # of dst ports */
  62                                                 /* in ports array (dst ports follow */
  63                                                 /* src ports; max of 10 ports in all; */
  64                                                 /* count of 0 means match all ports) */
  65 #define IP_FW_MAX_PORTS 10                      /* A reasonable maximum */
  66         unsigned short fw_pts[IP_FW_MAX_PORTS]; /* Array of port numbers to match */
  67         unsigned long  fw_pcnt,fw_bcnt;         /* Packet and byte counters */
  68         unsigned char  fw_tosand, fw_tosxor;    /* Revised packet priority */
  69         char           fw_vianame[IFNAMSIZ];    /* name of interface "via" */
  70 };
  71 
  72 /*
  73  *      Values for "flags" field .
  74  */
  75 
  76 #define IP_FW_F_ALL     0x000   /* This is a universal packet firewall*/
  77 #define IP_FW_F_TCP     0x001   /* This is a TCP packet firewall      */
  78 #define IP_FW_F_UDP     0x002   /* This is a UDP packet firewall      */
  79 #define IP_FW_F_ICMP    0x003   /* This is a ICMP packet firewall     */
  80 #define IP_FW_F_KIND    0x003   /* Mask to isolate firewall kind      */
  81 #define IP_FW_F_ACCEPT  0x004   /* This is an accept firewall (as     *
  82                                  *         opposed to a deny firewall)*
  83                                  *                                    */
  84 #define IP_FW_F_SRNG    0x008   /* The first two src ports are a min  *
  85                                  * and max range (stored in host byte *
  86                                  * order).                            *
  87                                  *                                    */
  88 #define IP_FW_F_DRNG    0x010   /* The first two dst ports are a min  *
  89                                  * and max range (stored in host byte *
  90                                  * order).                            *
  91                                  * (ports[0] <= port <= ports[1])     *
  92                                  *                                    */
  93 #define IP_FW_F_PRN     0x020   /* In verbose mode print this firewall*/
  94 #define IP_FW_F_BIDIR   0x040   /* For bidirectional firewalls        */
  95 #define IP_FW_F_TCPSYN  0x080   /* For tcp packets-check SYN only     */
  96 #define IP_FW_F_ICMPRPL 0x100   /* Send back icmp unreachable packet  */
  97 #define IP_FW_F_MASQ    0x200   /* Masquerading                       */
  98 #define IP_FW_F_TCPACK  0x400   /* For tcp-packets match if ACK is set*/
  99 
 100 #define IP_FW_F_MASK    0x7FF   /* All possible flag bits mask        */
 101 
 102 /*    
 103  *      New IP firewall options for [gs]etsockopt at the RAW IP level.
 104  *      Unlike BSD Linux inherits IP options so you don't have to use
 105  *      a raw socket for this. Instead we check rights in the calls.
 106  */     
 107 
 108 #define IP_FW_BASE_CTL          64      /* base for firewall socket options */
 109 
 110 #define IP_FW_COMMAND           0x00FF  /* mask for command without chain */
 111 #define IP_FW_TYPE              0x0300  /* mask for type (chain) */
 112 #define IP_FW_SHIFT             8       /* shift count for type (chain) */
 113 
 114 #define IP_FW_FWD               0
 115 #define IP_FW_IN                1
 116 #define IP_FW_OUT               2
 117 #define IP_FW_ACCT              3
 118 #define IP_FW_CHAINS            4       /* total number of ip_fw chains */
 119 
 120 #define IP_FW_INSERT            (IP_FW_BASE_CTL)
 121 #define IP_FW_APPEND            (IP_FW_BASE_CTL+1)
 122 #define IP_FW_DELETE            (IP_FW_BASE_CTL+2)
 123 #define IP_FW_FLUSH             (IP_FW_BASE_CTL+3)
 124 #define IP_FW_ZERO              (IP_FW_BASE_CTL+4)
 125 #define IP_FW_POLICY            (IP_FW_BASE_CTL+5)
 126 #define IP_FW_CHECK             (IP_FW_BASE_CTL+6)
 127 #define IP_FW_MASQ_TIMEOUTS     (IP_FW_BASE_CTL+7)
 128 
 129 #define IP_FW_INSERT_FWD        (IP_FW_INSERT | (IP_FW_FWD << IP_FW_SHIFT))
 130 #define IP_FW_APPEND_FWD        (IP_FW_APPEND | (IP_FW_FWD << IP_FW_SHIFT))
 131 #define IP_FW_DELETE_FWD        (IP_FW_DELETE | (IP_FW_FWD << IP_FW_SHIFT))
 132 #define IP_FW_FLUSH_FWD         (IP_FW_FLUSH  | (IP_FW_FWD << IP_FW_SHIFT))
 133 #define IP_FW_ZERO_FWD          (IP_FW_ZERO   | (IP_FW_FWD << IP_FW_SHIFT))
 134 #define IP_FW_POLICY_FWD        (IP_FW_POLICY | (IP_FW_FWD << IP_FW_SHIFT))
 135 #define IP_FW_CHECK_FWD         (IP_FW_CHECK  | (IP_FW_FWD << IP_FW_SHIFT))
 136 
 137 #define IP_FW_INSERT_IN         (IP_FW_INSERT | (IP_FW_IN << IP_FW_SHIFT))
 138 #define IP_FW_APPEND_IN         (IP_FW_APPEND | (IP_FW_IN << IP_FW_SHIFT))
 139 #define IP_FW_DELETE_IN         (IP_FW_DELETE | (IP_FW_IN << IP_FW_SHIFT))
 140 #define IP_FW_FLUSH_IN          (IP_FW_FLUSH  | (IP_FW_IN << IP_FW_SHIFT))
 141 #define IP_FW_ZERO_IN           (IP_FW_ZERO   | (IP_FW_IN << IP_FW_SHIFT))
 142 #define IP_FW_POLICY_IN         (IP_FW_POLICY | (IP_FW_IN << IP_FW_SHIFT))
 143 #define IP_FW_CHECK_IN          (IP_FW_CHECK  | (IP_FW_IN << IP_FW_SHIFT))
 144 
 145 #define IP_FW_INSERT_OUT        (IP_FW_INSERT | (IP_FW_OUT << IP_FW_SHIFT))
 146 #define IP_FW_APPEND_OUT        (IP_FW_APPEND | (IP_FW_OUT << IP_FW_SHIFT))
 147 #define IP_FW_DELETE_OUT        (IP_FW_DELETE | (IP_FW_OUT << IP_FW_SHIFT))
 148 #define IP_FW_FLUSH_OUT         (IP_FW_FLUSH  | (IP_FW_OUT << IP_FW_SHIFT))
 149 #define IP_FW_ZERO_OUT          (IP_FW_ZERO   | (IP_FW_OUT << IP_FW_SHIFT))
 150 #define IP_FW_POLICY_OUT        (IP_FW_POLICY | (IP_FW_OUT << IP_FW_SHIFT))
 151 #define IP_FW_CHECK_OUT         (IP_FW_CHECK  | (IP_FW_OUT << IP_FW_SHIFT))
 152 
 153 #define IP_ACCT_INSERT          (IP_FW_INSERT | (IP_FW_ACCT << IP_FW_SHIFT))
 154 #define IP_ACCT_APPEND          (IP_FW_APPEND | (IP_FW_ACCT << IP_FW_SHIFT))
 155 #define IP_ACCT_DELETE          (IP_FW_DELETE | (IP_FW_ACCT << IP_FW_SHIFT))
 156 #define IP_ACCT_FLUSH           (IP_FW_FLUSH  | (IP_FW_ACCT << IP_FW_SHIFT))
 157 #define IP_ACCT_ZERO            (IP_FW_ZERO   | (IP_FW_ACCT << IP_FW_SHIFT))
 158 
 159 struct ip_fwpkt
 160 {
 161         struct iphdr fwp_iph;                   /* IP header */
 162         union {
 163                 struct tcphdr fwp_tcph;         /* TCP header or */
 164                 struct udphdr fwp_udph;         /* UDP header */
 165                 struct icmphdr fwp_icmph;       /* ICMP header */
 166         } fwp_protoh;
 167         struct in_addr fwp_via;                 /* interface address */
 168         char           fwp_vianame[IFNAMSIZ];   /* interface name */
 169 };
 170 
 171 /*
 172  * timeouts for ip masquerading
 173  */
 174 
 175 struct ip_fw_masq;
 176 
 177 /*
 178  *      Main firewall chains definitions and global var's definitions.
 179  */
 180 
 181 #ifdef __KERNEL__
 182 
 183 #include <linux/config.h>
 184 #ifdef CONFIG_IP_FIREWALL
 185 extern struct ip_fw *ip_fw_in_chain;
 186 extern struct ip_fw *ip_fw_out_chain;
 187 extern struct ip_fw *ip_fw_fwd_chain;
 188 extern int ip_fw_in_policy;
 189 extern int ip_fw_out_policy;
 190 extern int ip_fw_fwd_policy;
 191 extern int ip_fw_ctl(int, void *, int);
 192 #endif
 193 #ifdef CONFIG_IP_ACCT
 194 extern struct ip_fw *ip_acct_chain;
 195 extern void ip_acct_cnt(struct iphdr *, struct device *, struct ip_fw *);
 196 extern int ip_acct_ctl(int, void *, int);
 197 #endif
 198 
 199 
 200 extern int ip_fw_chk(struct iphdr *, struct device *rif,struct ip_fw *, int, int);
 201 extern void ip_fw_init(void);
 202 #endif /* KERNEL */
 203 
 204 
 205 #endif /* _IP_FW_H */

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