nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * src/lib/ct.c CLI Conntrack Helpers |
||
3 | * |
||
4 | * This library is free software; you can redistribute it and/or |
||
5 | * modify it under the terms of the GNU Lesser General Public |
||
6 | * License as published by the Free Software Foundation version 2.1 |
||
7 | * of the License. |
||
8 | * |
||
9 | * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch> |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * @ingroup cli |
||
14 | * @defgroup cli_ct Connection Tracking |
||
15 | * |
||
16 | * @{ |
||
17 | */ |
||
18 | |||
19 | #include <netlink/cli/utils.h> |
||
20 | #include <netlink/cli/ct.h> |
||
21 | |||
22 | struct nfnl_ct *nl_cli_ct_alloc(void) |
||
23 | { |
||
24 | struct nfnl_ct *ct; |
||
25 | |||
26 | ct = nfnl_ct_alloc(); |
||
27 | if (!ct) |
||
28 | nl_cli_fatal(ENOMEM, "Unable to allocate conntrack object"); |
||
29 | |||
30 | return ct; |
||
31 | } |
||
32 | |||
33 | struct nl_cache *nl_cli_ct_alloc_cache(struct nl_sock *sk) |
||
34 | { |
||
35 | return nl_cli_alloc_cache(sk, "conntrack", nfnl_ct_alloc_cache); |
||
36 | } |
||
37 | |||
38 | void nl_cli_ct_parse_family(struct nfnl_ct *ct, char *arg) |
||
39 | { |
||
40 | int family; |
||
41 | |||
42 | if ((family = nl_str2af(arg)) == AF_UNSPEC) |
||
43 | nl_cli_fatal(EINVAL, |
||
44 | "Unable to nl_cli_ct_parse family \"%s\": %s", |
||
45 | arg, nl_geterror(NLE_INVAL)); |
||
46 | |||
47 | nfnl_ct_set_family(ct, family); |
||
48 | } |
||
49 | |||
50 | void nl_cli_ct_parse_protocol(struct nfnl_ct *ct, char *arg) |
||
51 | { |
||
52 | int proto; |
||
53 | |||
54 | if ((proto = nl_str2ip_proto(arg)) < 0) |
||
55 | nl_cli_fatal(proto, |
||
56 | "Unable to nl_cli_ct_parse protocol \"%s\": %s", |
||
57 | arg, nl_geterror(proto)); |
||
58 | |||
59 | nfnl_ct_set_proto(ct, proto); |
||
60 | } |
||
61 | |||
62 | void nl_cli_ct_parse_mark(struct nfnl_ct *ct, char *arg) |
||
63 | { |
||
64 | uint32_t mark = nl_cli_parse_u32(arg); |
||
65 | nfnl_ct_set_mark(ct, mark); |
||
66 | } |
||
67 | |||
68 | void nl_cli_ct_parse_timeout(struct nfnl_ct *ct, char *arg) |
||
69 | { |
||
70 | uint32_t timeout = nl_cli_parse_u32(arg); |
||
71 | nfnl_ct_set_timeout(ct, timeout); |
||
72 | } |
||
73 | |||
74 | void nl_cli_ct_parse_id(struct nfnl_ct *ct, char *arg) |
||
75 | { |
||
76 | uint32_t id = nl_cli_parse_u32(arg); |
||
77 | nfnl_ct_set_id(ct, id); |
||
78 | } |
||
79 | |||
80 | void nl_cli_ct_parse_use(struct nfnl_ct *ct, char *arg) |
||
81 | { |
||
82 | uint32_t use = nl_cli_parse_u32(arg); |
||
83 | nfnl_ct_set_use(ct, use); |
||
84 | } |
||
85 | |||
86 | void nl_cli_ct_parse_src(struct nfnl_ct *ct, int reply, char *arg) |
||
87 | { |
||
88 | int err; |
||
89 | struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct)); |
||
90 | if ((err = nfnl_ct_set_src(ct, reply, a)) < 0) |
||
91 | nl_cli_fatal(err, "Unable to set source address: %s", |
||
92 | nl_geterror(err)); |
||
93 | } |
||
94 | |||
95 | void nl_cli_ct_parse_dst(struct nfnl_ct *ct, int reply, char *arg) |
||
96 | { |
||
97 | int err; |
||
98 | struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct)); |
||
99 | if ((err = nfnl_ct_set_dst(ct, reply, a)) < 0) |
||
100 | nl_cli_fatal(err, "Unable to set destination address: %s", |
||
101 | nl_geterror(err)); |
||
102 | } |
||
103 | |||
104 | void nl_cli_ct_parse_src_port(struct nfnl_ct *ct, int reply, char *arg) |
||
105 | { |
||
106 | uint32_t port = nl_cli_parse_u32(arg); |
||
107 | nfnl_ct_set_src_port(ct, reply, port); |
||
108 | } |
||
109 | |||
110 | void nl_cli_ct_parse_dst_port(struct nfnl_ct *ct, int reply, char *arg) |
||
111 | { |
||
112 | uint32_t port = nl_cli_parse_u32(arg); |
||
113 | nfnl_ct_set_dst_port(ct, reply, port); |
||
114 | } |
||
115 | |||
116 | void nl_cli_ct_parse_tcp_state(struct nfnl_ct *ct, char *arg) |
||
117 | { |
||
118 | int state; |
||
119 | |||
120 | if ((state = nfnl_ct_str2tcp_state(arg)) < 0) |
||
121 | nl_cli_fatal(state, |
||
122 | "Unable to nl_cli_ct_parse tcp state \"%s\": %s", |
||
123 | arg, nl_geterror(state)); |
||
124 | |||
125 | nfnl_ct_set_tcp_state(ct, state); |
||
126 | } |
||
127 | |||
128 | void nl_cli_ct_parse_status(struct nfnl_ct *ct, char *arg) |
||
129 | { |
||
130 | int status; |
||
131 | |||
132 | if ((status = nfnl_ct_str2status(arg)) < 0) |
||
133 | nl_cli_fatal(status, |
||
134 | "Unable to nl_cli_ct_parse flags \"%s\": %s", |
||
135 | arg, nl_geterror(status)); |
||
136 | |||
137 | nfnl_ct_set_status(ct, status); |
||
138 | } |
||
139 | |||
140 | #if 0 |
||
141 | } else if (arg_match("origicmpid")) { |
||
142 | if (argc > ++idx) |
||
143 | nfnl_ct_set_icmp_id(ct, 0, strtoul(argv[idx++], NULL, 0)); |
||
144 | } else if (arg_match("origicmptype")) { |
||
145 | if (argc > ++idx) |
||
146 | nfnl_ct_set_icmp_type(ct, 0, strtoul(argv[idx++], NULL, 0)); |
||
147 | } else if (arg_match("origicmpcode")) { |
||
148 | if (argc > ++idx) |
||
149 | nfnl_ct_set_icmp_code(ct, 0, strtoul(argv[idx++], NULL, 0)); |
||
150 | } else if (arg_match("replyicmpid")) { |
||
151 | if (argc > ++idx) |
||
152 | nfnl_ct_set_icmp_id(ct, 1, strtoul(argv[idx++], NULL, 0)); |
||
153 | } else if (arg_match("replyicmptype")) { |
||
154 | if (argc > ++idx) |
||
155 | nfnl_ct_set_icmp_type(ct, 1, strtoul(argv[idx++], NULL, 0)); |
||
156 | } else if (arg_match("replyicmpcode")) { |
||
157 | if (argc > ++idx) |
||
158 | nfnl_ct_set_icmp_code(ct, 1, strtoul(argv[idx++], NULL, 0)); |
||
159 | } |
||
160 | #endif |
||
161 | |||
162 | /** @} */ |