File: ct.c

package info (click to toggle)
libnl3 3.4.0-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,120 kB
  • sloc: ansic: 57,494; sh: 4,447; python: 3,702; makefile: 888; yacc: 478; cpp: 454; lex: 210
file content (168 lines) | stat: -rw-r--r-- 4,173 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * src/lib/ct.c		CLI Conntrack Helpers
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation version 2.1
 *	of the License.
 *
 * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch>
 */

/**
 * @ingroup cli
 * @defgroup cli_ct Connection Tracking
 *
 * @{
 */

#include <netlink/cli/utils.h>
#include <netlink/cli/ct.h>

struct nfnl_ct *nl_cli_ct_alloc(void)
{
	struct nfnl_ct *ct;

	ct = nfnl_ct_alloc();
	if (!ct)
		nl_cli_fatal(ENOMEM, "Unable to allocate conntrack object");

	return ct;
}

struct nl_cache *nl_cli_ct_alloc_cache(struct nl_sock *sk)
{
	return nl_cli_alloc_cache(sk, "conntrack", nfnl_ct_alloc_cache);
}

void nl_cli_ct_parse_family(struct nfnl_ct *ct, char *arg)
{
	int family;

	if ((family = nl_str2af(arg)) == AF_UNSPEC)
		nl_cli_fatal(EINVAL,
			     "Unable to nl_cli_ct_parse family \"%s\": %s",
			     arg, nl_geterror(NLE_INVAL));

	nfnl_ct_set_family(ct, family);
}

void nl_cli_ct_parse_protocol(struct nfnl_ct *ct, char *arg)
{
	int proto;

	if ((proto = nl_str2ip_proto(arg)) < 0)
		nl_cli_fatal(proto,
			     "Unable to nl_cli_ct_parse protocol \"%s\": %s",
			     arg, nl_geterror(proto));

	nfnl_ct_set_proto(ct, proto);
}

void nl_cli_ct_parse_mark(struct nfnl_ct *ct, char *arg)
{
	uint32_t mark = nl_cli_parse_u32(arg);
	nfnl_ct_set_mark(ct, mark);
}

void nl_cli_ct_parse_timeout(struct nfnl_ct *ct, char *arg)
{
	uint32_t timeout = nl_cli_parse_u32(arg);
	nfnl_ct_set_timeout(ct, timeout);
}

void nl_cli_ct_parse_id(struct nfnl_ct *ct, char *arg)
{
	uint32_t id = nl_cli_parse_u32(arg);
	nfnl_ct_set_id(ct, id);
}

void nl_cli_ct_parse_use(struct nfnl_ct *ct, char *arg)
{
	uint32_t use = nl_cli_parse_u32(arg);
	nfnl_ct_set_use(ct, use);
}

void nl_cli_ct_parse_src(struct nfnl_ct *ct, int reply, char *arg)
{
	int err;
	struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct));
	if ((err = nfnl_ct_set_src(ct, reply, a)) < 0)
		nl_cli_fatal(err, "Unable to set source address: %s",
			     nl_geterror(err));
}

void nl_cli_ct_parse_dst(struct nfnl_ct *ct, int reply, char *arg)
{
	int err;
	struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct));
	if ((err = nfnl_ct_set_dst(ct, reply, a)) < 0)
		nl_cli_fatal(err, "Unable to set destination address: %s",
			     nl_geterror(err));
}

void nl_cli_ct_parse_src_port(struct nfnl_ct *ct, int reply, char *arg)
{
	uint32_t port = nl_cli_parse_u32(arg);
	nfnl_ct_set_src_port(ct, reply, port);
}

void nl_cli_ct_parse_dst_port(struct nfnl_ct *ct, int reply, char *arg)
{
	uint32_t port = nl_cli_parse_u32(arg);
	nfnl_ct_set_dst_port(ct, reply, port);
}

void nl_cli_ct_parse_tcp_state(struct nfnl_ct *ct, char *arg)
{
	int state;

	if ((state = nfnl_ct_str2tcp_state(arg)) < 0)
		nl_cli_fatal(state,
			     "Unable to nl_cli_ct_parse tcp state \"%s\": %s",
			     arg, nl_geterror(state));

	nfnl_ct_set_tcp_state(ct, state);
}

void nl_cli_ct_parse_status(struct nfnl_ct *ct, char *arg)
{
	int status;

	if ((status = nfnl_ct_str2status(arg)) < 0)
		nl_cli_fatal(status,
			     "Unable to nl_cli_ct_parse flags \"%s\": %s",
			     arg, nl_geterror(status));

	nfnl_ct_set_status(ct, status);
}

void nl_cli_ct_parse_zone(struct nfnl_ct *ct, char *arg)
{
	uint32_t zone = nl_cli_parse_u32(arg);
	nfnl_ct_set_zone(ct, zone);
}

#if 0
		} else if (arg_match("origicmpid")) {
			if (argc > ++idx)
				nfnl_ct_set_icmp_id(ct, 0, strtoul(argv[idx++], NULL, 0));
		} else if (arg_match("origicmptype")) {
			if (argc > ++idx)
				nfnl_ct_set_icmp_type(ct, 0, strtoul(argv[idx++], NULL, 0));
		} else if (arg_match("origicmpcode")) {
			if (argc > ++idx)
				nfnl_ct_set_icmp_code(ct, 0, strtoul(argv[idx++], NULL, 0));
		} else if (arg_match("replyicmpid")) {
			if (argc > ++idx)
				nfnl_ct_set_icmp_id(ct, 1, strtoul(argv[idx++], NULL, 0));
		} else if (arg_match("replyicmptype")) {
			if (argc > ++idx)
				nfnl_ct_set_icmp_type(ct, 1, strtoul(argv[idx++], NULL, 0));
		} else if (arg_match("replyicmpcode")) {
			if (argc > ++idx)
				nfnl_ct_set_icmp_code(ct, 1, strtoul(argv[idx++], NULL, 0));
		}
#endif

/** @} */