00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <netlink/cli/utils.h>
00020 #include <netlink/cli/ct.h>
00021
00022 struct nfnl_ct *nl_cli_ct_alloc(void)
00023 {
00024 struct nfnl_ct *ct;
00025
00026 ct = nfnl_ct_alloc();
00027 if (!ct)
00028 nl_cli_fatal(ENOMEM, "Unable to allocate conntrack object");
00029
00030 return ct;
00031 }
00032
00033 struct nl_cache *nl_cli_ct_alloc_cache(struct nl_sock *sk)
00034 {
00035 return nl_cli_alloc_cache(sk, "conntrack", nfnl_ct_alloc_cache);
00036 }
00037
00038 void nl_cli_ct_parse_family(struct nfnl_ct *ct, char *arg)
00039 {
00040 int family;
00041
00042 if ((family = nl_str2af(arg)) == AF_UNSPEC)
00043 nl_cli_fatal(EINVAL,
00044 "Unable to nl_cli_ct_parse family \"%s\": %s",
00045 arg, nl_geterror(NLE_INVAL));
00046
00047 nfnl_ct_set_family(ct, family);
00048 }
00049
00050 void nl_cli_ct_parse_protocol(struct nfnl_ct *ct, char *arg)
00051 {
00052 int proto;
00053
00054 if ((proto = nl_str2ip_proto(arg)) < 0)
00055 nl_cli_fatal(proto,
00056 "Unable to nl_cli_ct_parse protocol \"%s\": %s",
00057 arg, nl_geterror(proto));
00058
00059 nfnl_ct_set_proto(ct, proto);
00060 }
00061
00062 void nl_cli_ct_parse_mark(struct nfnl_ct *ct, char *arg)
00063 {
00064 uint32_t mark = nl_cli_parse_u32(arg);
00065 nfnl_ct_set_mark(ct, mark);
00066 }
00067
00068 void nl_cli_ct_parse_timeout(struct nfnl_ct *ct, char *arg)
00069 {
00070 uint32_t timeout = nl_cli_parse_u32(arg);
00071 nfnl_ct_set_timeout(ct, timeout);
00072 }
00073
00074 void nl_cli_ct_parse_id(struct nfnl_ct *ct, char *arg)
00075 {
00076 uint32_t id = nl_cli_parse_u32(arg);
00077 nfnl_ct_set_id(ct, id);
00078 }
00079
00080 void nl_cli_ct_parse_use(struct nfnl_ct *ct, char *arg)
00081 {
00082 uint32_t use = nl_cli_parse_u32(arg);
00083 nfnl_ct_set_use(ct, use);
00084 }
00085
00086 void nl_cli_ct_parse_src(struct nfnl_ct *ct, int reply, char *arg)
00087 {
00088 int err;
00089 struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct));
00090 if ((err = nfnl_ct_set_src(ct, reply, a)) < 0)
00091 nl_cli_fatal(err, "Unable to set source address: %s",
00092 nl_geterror(err));
00093 }
00094
00095 void nl_cli_ct_parse_dst(struct nfnl_ct *ct, int reply, char *arg)
00096 {
00097 int err;
00098 struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct));
00099 if ((err = nfnl_ct_set_dst(ct, reply, a)) < 0)
00100 nl_cli_fatal(err, "Unable to set destination address: %s",
00101 nl_geterror(err));
00102 }
00103
00104 void nl_cli_ct_parse_src_port(struct nfnl_ct *ct, int reply, char *arg)
00105 {
00106 uint32_t port = nl_cli_parse_u32(arg);
00107 nfnl_ct_set_src_port(ct, reply, port);
00108 }
00109
00110 void nl_cli_ct_parse_dst_port(struct nfnl_ct *ct, int reply, char *arg)
00111 {
00112 uint32_t port = nl_cli_parse_u32(arg);
00113 nfnl_ct_set_dst_port(ct, reply, port);
00114 }
00115
00116 void nl_cli_ct_parse_tcp_state(struct nfnl_ct *ct, char *arg)
00117 {
00118 int state;
00119
00120 if ((state = nfnl_ct_str2tcp_state(arg)) < 0)
00121 nl_cli_fatal(state,
00122 "Unable to nl_cli_ct_parse tcp state \"%s\": %s",
00123 arg, nl_geterror(state));
00124
00125 nfnl_ct_set_tcp_state(ct, state);
00126 }
00127
00128 void nl_cli_ct_parse_status(struct nfnl_ct *ct, char *arg)
00129 {
00130 int status;
00131
00132 if ((status = nfnl_ct_str2status(arg)) < 0)
00133 nl_cli_fatal(status,
00134 "Unable to nl_cli_ct_parse flags \"%s\": %s",
00135 arg, nl_geterror(status));
00136
00137 nfnl_ct_set_status(ct, status);
00138 }
00139
00140 #if 0
00141 } else if (arg_match("origicmpid")) {
00142 if (argc > ++idx)
00143 nfnl_ct_set_icmp_id(ct, 0, strtoul(argv[idx++], NULL, 0));
00144 } else if (arg_match("origicmptype")) {
00145 if (argc > ++idx)
00146 nfnl_ct_set_icmp_type(ct, 0, strtoul(argv[idx++], NULL, 0));
00147 } else if (arg_match("origicmpcode")) {
00148 if (argc > ++idx)
00149 nfnl_ct_set_icmp_code(ct, 0, strtoul(argv[idx++], NULL, 0));
00150 } else if (arg_match("replyicmpid")) {
00151 if (argc > ++idx)
00152 nfnl_ct_set_icmp_id(ct, 1, strtoul(argv[idx++], NULL, 0));
00153 } else if (arg_match("replyicmptype")) {
00154 if (argc > ++idx)
00155 nfnl_ct_set_icmp_type(ct, 1, strtoul(argv[idx++], NULL, 0));
00156 } else if (arg_match("replyicmpcode")) {
00157 if (argc > ++idx)
00158 nfnl_ct_set_icmp_code(ct, 1, strtoul(argv[idx++], NULL, 0));
00159 }
00160 #endif
00161
00162