Back to home page

LXR

 
 

    


0001 #ifndef _UAPI_X_TABLES_H
0002 #define _UAPI_X_TABLES_H
0003 #include <linux/kernel.h>
0004 #include <linux/types.h>
0005 
0006 #define XT_FUNCTION_MAXNAMELEN 30
0007 #define XT_EXTENSION_MAXNAMELEN 29
0008 #define XT_TABLE_MAXNAMELEN 32
0009 
0010 struct xt_entry_match {
0011     union {
0012         struct {
0013             __u16 match_size;
0014 
0015             /* Used by userspace */
0016             char name[XT_EXTENSION_MAXNAMELEN];
0017             __u8 revision;
0018         } user;
0019         struct {
0020             __u16 match_size;
0021 
0022             /* Used inside the kernel */
0023             struct xt_match *match;
0024         } kernel;
0025 
0026         /* Total length */
0027         __u16 match_size;
0028     } u;
0029 
0030     unsigned char data[0];
0031 };
0032 
0033 struct xt_entry_target {
0034     union {
0035         struct {
0036             __u16 target_size;
0037 
0038             /* Used by userspace */
0039             char name[XT_EXTENSION_MAXNAMELEN];
0040             __u8 revision;
0041         } user;
0042         struct {
0043             __u16 target_size;
0044 
0045             /* Used inside the kernel */
0046             struct xt_target *target;
0047         } kernel;
0048 
0049         /* Total length */
0050         __u16 target_size;
0051     } u;
0052 
0053     unsigned char data[0];
0054 };
0055 
0056 #define XT_TARGET_INIT(__name, __size)                         \
0057 {                                          \
0058     .target.u.user = {                             \
0059         .target_size    = XT_ALIGN(__size),                \
0060         .name       = __name,                      \
0061     },                                     \
0062 }
0063 
0064 struct xt_standard_target {
0065     struct xt_entry_target target;
0066     int verdict;
0067 };
0068 
0069 struct xt_error_target {
0070     struct xt_entry_target target;
0071     char errorname[XT_FUNCTION_MAXNAMELEN];
0072 };
0073 
0074 /* The argument to IPT_SO_GET_REVISION_*.  Returns highest revision
0075  * kernel supports, if >= revision. */
0076 struct xt_get_revision {
0077     char name[XT_EXTENSION_MAXNAMELEN];
0078     __u8 revision;
0079 };
0080 
0081 /* CONTINUE verdict for targets */
0082 #define XT_CONTINUE 0xFFFFFFFF
0083 
0084 /* For standard target */
0085 #define XT_RETURN (-NF_REPEAT - 1)
0086 
0087 /* this is a dummy structure to find out the alignment requirement for a struct
0088  * containing all the fundamental data types that are used in ipt_entry,
0089  * ip6t_entry and arpt_entry.  This sucks, and it is a hack.  It will be my
0090  * personal pleasure to remove it -HW
0091  */
0092 struct _xt_align {
0093     __u8 u8;
0094     __u16 u16;
0095     __u32 u32;
0096     __u64 u64;
0097 };
0098 
0099 #define XT_ALIGN(s) __ALIGN_KERNEL((s), __alignof__(struct _xt_align))
0100 
0101 /* Standard return verdict, or do jump. */
0102 #define XT_STANDARD_TARGET ""
0103 /* Error verdict. */
0104 #define XT_ERROR_TARGET "ERROR"
0105 
0106 #define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0)
0107 #define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0)
0108 
0109 struct xt_counters {
0110     __u64 pcnt, bcnt;           /* Packet and byte counters */
0111 };
0112 
0113 /* The argument to IPT_SO_ADD_COUNTERS. */
0114 struct xt_counters_info {
0115     /* Which table. */
0116     char name[XT_TABLE_MAXNAMELEN];
0117 
0118     unsigned int num_counters;
0119 
0120     /* The counters (actually `number' of these). */
0121     struct xt_counters counters[0];
0122 };
0123 
0124 #define XT_INV_PROTO        0x40    /* Invert the sense of PROTO. */
0125 
0126 #ifndef __KERNEL__
0127 /* fn returns 0 to continue iteration */
0128 #define XT_MATCH_ITERATE(type, e, fn, args...)          \
0129 ({                              \
0130     unsigned int __i;                   \
0131     int __ret = 0;                      \
0132     struct xt_entry_match *__m;             \
0133                                 \
0134     for (__i = sizeof(type);                \
0135          __i < (e)->target_offset;              \
0136          __i += __m->u.match_size) {            \
0137         __m = (void *)e + __i;              \
0138                                 \
0139         __ret = fn(__m , ## args);          \
0140         if (__ret != 0)                 \
0141             break;                  \
0142     }                           \
0143     __ret;                          \
0144 })
0145 
0146 /* fn returns 0 to continue iteration */
0147 #define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \
0148 ({                              \
0149     unsigned int __i, __n;                  \
0150     int __ret = 0;                      \
0151     type *__entry;                      \
0152                                 \
0153     for (__i = 0, __n = 0; __i < (size);            \
0154          __i += __entry->next_offset, __n++) {      \
0155         __entry = (void *)(entries) + __i;      \
0156         if (__n < n)                    \
0157             continue;               \
0158                                 \
0159         __ret = fn(__entry , ## args);          \
0160         if (__ret != 0)                 \
0161             break;                  \
0162     }                           \
0163     __ret;                          \
0164 })
0165 
0166 /* fn returns 0 to continue iteration */
0167 #define XT_ENTRY_ITERATE(type, entries, size, fn, args...) \
0168     XT_ENTRY_ITERATE_CONTINUE(type, entries, size, 0, fn, args)
0169 
0170 #endif /* !__KERNEL__ */
0171 
0172 /* pos is normally a struct ipt_entry/ip6t_entry/etc. */
0173 #define xt_entry_foreach(pos, ehead, esize) \
0174     for ((pos) = (typeof(pos))(ehead); \
0175          (pos) < (typeof(pos))((char *)(ehead) + (esize)); \
0176          (pos) = (typeof(pos))((char *)(pos) + (pos)->next_offset))
0177 
0178 /* can only be xt_entry_match, so no use of typeof here */
0179 #define xt_ematch_foreach(pos, entry) \
0180     for ((pos) = (struct xt_entry_match *)entry->elems; \
0181          (pos) < (struct xt_entry_match *)((char *)(entry) + \
0182                  (entry)->target_offset); \
0183          (pos) = (struct xt_entry_match *)((char *)(pos) + \
0184                  (pos)->u.match_size))
0185 
0186 
0187 #endif /* _UAPI_X_TABLES_H */