netfilter 锁开销_netfilter_netfilter 无锁(7)

电脑杂谈  发布时间:2017-02-27 02:09:24  来源:网络整理

// 第4个参数表示该选项的索引值

static struct option opts[] = {

{ "set-id", 1, 0, '1' },

{ 0 }

};

/* Initialize the target. */

static void

init(struct ipt_entry_target *t, unsigned int *nfcache)

{

// 空函数,不需要预处理

}

static void

parse_id(const unsigned char *s, struct ipt_id_target_info*info)

{

unsigned int i, id;

if (string_to_number(s, 0, 255, &id) != -1) {

// 注意要将主机序数据转换为网络序

info->id = htons((u_int16_t)id);

return;

}

exit_error(PARAMETER_PROBLEM, "Bad ID value `%s'", s);

}

/* Function which parses command options; returns true if it

ate an option */

static int

parse(int c, char **argv, int invert, unsigned int *flags,

const struct ipt_entry *entry,

struct ipt_entry_target**target)

{

struct ipt_id_target_info *idinfo

= (struct ipt_id_target_info *)(*target)->data;

switch (c) {

case '1':

if (*flags)

exit_error(PARAMETER_PROBLEM,

"ID target: Cant specify --set-id twice");

parse_id(optarg, idinfo);

*flags = 1;

break;

default:

return 0;

}

return 1;

}

static void

final_check(unsigned int flags)

{

if (!flags)

exit_error(PARAMETER_PROBLEM,

"ID target: Parameter --set-id is required");

}

static void

print_id(u_int8_t id, int numeric)

{

unsigned int i;

printf("0x%x ", ntohs(id));

}

/* Prints out the targinfo. */

static void

print(const struct ipt_ip *ip,

const struct ipt_entry_target*target,

int numeric)

{

const struct ipt_id_target_info *idinfo =

(const struct ipt_id_target_info *)target->data;

printf("ID set ");

print_id(idinfo->id, numeric);

}

/* Saves the union ipt_targinfo in parsable form to stdout.*/


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-34719-7.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...