diff options
author | jk7744.park <jk7744.park@samsung.com> | 2015-09-08 21:56:24 +0900 |
---|---|---|
committer | jk7744.park <jk7744.park@samsung.com> | 2015-09-08 21:56:24 +0900 |
commit | 427e21006a01f98c92434008442bba504c9d2e6c (patch) | |
tree | 8d3cdcc6e535016586023d74b9816ef339ddb31f /extensions/libxt_DSCP.c | |
parent | f5589e19420a83ca978348cbcfbc4c83b310bd3b (diff) | |
download | iptables-tizen_2.3.1.tar.gz iptables-tizen_2.3.1.tar.bz2 iptables-tizen_2.3.1.zip |
tizen 2.3.1 releasetizen_2.3.1_releasesubmit/tizen_2.3.1/20150915.074541tizen_2.3.1
Diffstat (limited to 'extensions/libxt_DSCP.c')
-rw-r--r-- | extensions/libxt_DSCP.c | 97 |
1 files changed, 30 insertions, 67 deletions
diff --git a/extensions/libxt_DSCP.c b/extensions/libxt_DSCP.c index 82ac10c..e16e93c 100644 --- a/extensions/libxt_DSCP.c +++ b/extensions/libxt_DSCP.c @@ -11,16 +11,19 @@ */ #include <stdio.h> #include <string.h> -#include <stdlib.h> -#include <getopt.h> - #include <xtables.h> -#include <linux/netfilter/x_tables.h> #include <linux/netfilter/xt_DSCP.h> /* This is evil, but it's my code - HW*/ #include "dscp_helper.c" +enum { + O_SET_DSCP = 0, + O_SET_DSCP_CLASS, + F_SET_DSCP = 1 << O_SET_DSCP, + F_SET_DSCP_CLASS = 1 << O_SET_DSCP_CLASS, +}; + static void DSCP_help(void) { printf( @@ -37,79 +40,39 @@ static void DSCP_help(void) ); } -static const struct option DSCP_opts[] = { - { "set-dscp", 1, NULL, 'F' }, - { "set-dscp-class", 1, NULL, 'G' }, - { .name = NULL } +static const struct xt_option_entry DSCP_opts[] = { + {.name = "set-dscp", .id = O_SET_DSCP, .excl = F_SET_DSCP_CLASS, + .type = XTTYPE_UINT8, .min = 0, .max = XT_DSCP_MAX, + .flags = XTOPT_PUT, + XTOPT_POINTER(struct xt_DSCP_info, dscp)}, + {.name = "set-dscp-class", .id = O_SET_DSCP_CLASS, .excl = F_SET_DSCP, + .type = XTTYPE_STRING}, + XTOPT_TABLEEND, }; -static void -parse_dscp(const char *s, struct xt_DSCP_info *dinfo) +static void DSCP_parse(struct xt_option_call *cb) { - unsigned int dscp; - - if (!xtables_strtoui(s, NULL, &dscp, 0, UINT8_MAX)) - xtables_error(PARAMETER_PROBLEM, - "Invalid dscp `%s'\n", s); + struct xt_DSCP_info *dinfo = cb->data; - if (dscp > XT_DSCP_MAX) - xtables_error(PARAMETER_PROBLEM, - "DSCP `%d` out of range\n", dscp); - - dinfo->dscp = dscp; -} - - -static void -parse_class(const char *s, struct xt_DSCP_info *dinfo) -{ - unsigned int dscp = class_to_dscp(s); - - /* Assign the value */ - dinfo->dscp = dscp; -} - - -static int DSCP_parse(int c, char **argv, int invert, unsigned int *flags, - const void *entry, struct xt_entry_target **target) -{ - struct xt_DSCP_info *dinfo - = (struct xt_DSCP_info *)(*target)->data; - - switch (c) { - case 'F': - if (*flags) - xtables_error(PARAMETER_PROBLEM, - "DSCP target: Only use --set-dscp ONCE!"); - parse_dscp(optarg, dinfo); - *flags = 1; - break; - case 'G': - if (*flags) - xtables_error(PARAMETER_PROBLEM, - "DSCP target: Only use --set-dscp-class ONCE!"); - parse_class(optarg, dinfo); - *flags = 1; + xtables_option_parse(cb); + switch (cb->entry->id) { + case O_SET_DSCP_CLASS: + dinfo->dscp = class_to_dscp(cb->arg); break; - - default: - return 0; } - - return 1; } -static void DSCP_check(unsigned int flags) +static void DSCP_check(struct xt_fcheck_call *cb) { - if (!flags) + if (cb->xflags == 0) xtables_error(PARAMETER_PROBLEM, "DSCP target: Parameter --set-dscp is required"); } static void -print_dscp(u_int8_t dscp, int numeric) +print_dscp(uint8_t dscp, int numeric) { - printf("0x%02x ", dscp); + printf(" 0x%02x", dscp); } static void DSCP_print(const void *ip, const struct xt_entry_target *target, @@ -117,7 +80,7 @@ static void DSCP_print(const void *ip, const struct xt_entry_target *target, { const struct xt_DSCP_info *dinfo = (const struct xt_DSCP_info *)target->data; - printf("DSCP set "); + printf(" DSCP set"); print_dscp(dinfo->dscp, numeric); } @@ -126,7 +89,7 @@ static void DSCP_save(const void *ip, const struct xt_entry_target *target) const struct xt_DSCP_info *dinfo = (const struct xt_DSCP_info *)target->data; - printf("--set-dscp 0x%02x ", dinfo->dscp); + printf(" --set-dscp 0x%02x", dinfo->dscp); } static struct xtables_target dscp_target = { @@ -136,11 +99,11 @@ static struct xtables_target dscp_target = { .size = XT_ALIGN(sizeof(struct xt_DSCP_info)), .userspacesize = XT_ALIGN(sizeof(struct xt_DSCP_info)), .help = DSCP_help, - .parse = DSCP_parse, - .final_check = DSCP_check, .print = DSCP_print, .save = DSCP_save, - .extra_opts = DSCP_opts, + .x6_parse = DSCP_parse, + .x6_fcheck = DSCP_check, + .x6_options = DSCP_opts, }; void _init(void) |