• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/firewall3/xtables-10.h

  1 /*
  2  * firewall3 - 3rd OpenWrt UCI firewall implementation
  3  *
  4  *   Copyright (C) 2013 Jo-Philipp Wich <jo@mein.io>
  5  *
  6  * Permission to use, copy, modify, and/or distribute this software for any
  7  * purpose with or without fee is hereby granted, provided that the above
  8  * copyright notice and this permission notice appear in all copies.
  9  *
 10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 17  */
 18 
 19 #ifndef __FW3_XTABLES_10_H
 20 #define __FW3_XTABLES_10_H
 21 
 22 extern struct xtables_match *xtables_pending_matches;
 23 extern struct xtables_target *xtables_pending_targets;
 24 
 25 static inline void
 26 fw3_xt_reset(void)
 27 {
 28         xtables_matches = NULL;
 29         xtables_targets = NULL;
 30 
 31         xtables_pending_matches = NULL;
 32         xtables_pending_targets = NULL;
 33 }
 34 
 35 
 36 static inline const char *
 37 fw3_xt_get_match_name(struct xtables_match *m)
 38 {
 39     if (m->alias)
 40         return m->alias(m->m);
 41 
 42     return m->m->u.user.name;
 43 }
 44 
 45 static inline void
 46 fw3_xt_set_match_name(struct xtables_match *m)
 47 {
 48     if (m->real_name)
 49         strcpy(m->m->u.user.name, m->real_name);
 50     else
 51         strcpy(m->m->u.user.name, m->name);
 52 }
 53 
 54 static inline bool
 55 fw3_xt_has_match_parse(struct xtables_match *m)
 56 {
 57     return (m->parse || m->x6_parse);
 58 }
 59 
 60 static inline void
 61 fw3_xt_free_match_udata(struct xtables_match *m)
 62 {
 63     if (m->udata_size)
 64     {
 65         free(m->udata);
 66         m->udata = fw3_alloc(m->udata_size);
 67     }
 68 }
 69 
 70 static inline void
 71 fw3_xt_merge_match_options(struct xtables_globals *g, struct xtables_match *m)
 72 {
 73         if (m->x6_options)
 74                 g->opts = xtables_options_xfrm(g->orig_opts, g->opts,
 75                                                                            m->x6_options, &m->option_offset);
 76 
 77         if (m->extra_opts)
 78                 g->opts = xtables_merge_options(g->orig_opts, g->opts,
 79                                                                                 m->extra_opts, &m->option_offset);
 80 }
 81 
 82 
 83 static inline const char *
 84 fw3_xt_get_target_name(struct xtables_target *t)
 85 {
 86     if (t->alias)
 87         return t->alias(t->t);
 88 
 89     return t->t->u.user.name;
 90 }
 91 
 92 static inline void
 93 fw3_xt_set_target_name(struct xtables_target *t, const char *name)
 94 {
 95     if (t->real_name)
 96         strcpy(t->t->u.user.name, t->real_name);
 97     else
 98         strcpy(t->t->u.user.name, name);
 99 }
100 
101 static inline bool
102 fw3_xt_has_target_parse(struct xtables_target *t)
103 {
104     return (t->parse || t->x6_parse);
105 }
106 
107 static inline void
108 fw3_xt_free_target_udata(struct xtables_target *t)
109 {
110     if (t->udata_size)
111     {
112         free(t->udata);
113         t->udata = fw3_alloc(t->udata_size);
114     }
115 }
116 
117 static inline void
118 fw3_xt_merge_target_options(struct xtables_globals *g, struct xtables_target *t)
119 {
120         if (t->x6_options)
121                 g->opts = xtables_options_xfrm(g->orig_opts, g->opts,
122                                                t->x6_options, &t->option_offset);
123         else
124                 g->opts = xtables_merge_options(g->orig_opts, g->opts,
125                                                 t->extra_opts, &t->option_offset);
126 }
127 
128 static inline void
129 fw3_xt_print_matches(void *ip, struct xtables_rule_match *matches)
130 {
131         struct xtables_rule_match *rm;
132         struct xtables_match *m;
133 
134         for (rm = matches; rm; rm = rm->next)
135         {
136                 m = rm->match;
137                 printf(" -m %s", fw3_xt_get_match_name(m));
138 
139                 if (m->save)
140                         m->save(ip, m->m);
141         }
142 }
143 
144 static inline void
145 fw3_xt_print_target(void *ip, struct xtables_target *target)
146 {
147         if (target)
148         {
149                 printf(" -j %s", fw3_xt_get_target_name(target));
150 
151                 if (target->save)
152                         target->save(ip, target->t);
153         }
154 }
155 
156 #endif
157 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt