summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/datatype.c10
-rw-r--r--src/libnftables.c8
-rw-r--r--src/main.c25
3 files changed, 32 insertions, 11 deletions
diff --git a/src/datatype.c b/src/datatype.c
index 20904453..fbc3ac35 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -454,7 +454,7 @@ static void ipaddr_type_print(const struct expr *expr, struct output_ctx *octx)
sin.sin_addr.s_addr = mpz_get_be32(expr->value);
err = getnameinfo((struct sockaddr *)&sin, sizeof(sin), buf,
sizeof(buf), NULL, 0,
- octx->ip2name ? 0 : NI_NUMERICHOST);
+ octx->literal >= NFT_LITERAL_ADDR ? 0 : NI_NUMERICHOST);
if (err != 0) {
getnameinfo((struct sockaddr *)&sin, sizeof(sin), buf,
sizeof(buf), NULL, 0, NI_NUMERICHOST);
@@ -512,7 +512,7 @@ static void ip6addr_type_print(const struct expr *expr, struct output_ctx *octx)
err = getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), buf,
sizeof(buf), NULL, 0,
- octx->ip2name ? 0 : NI_NUMERICHOST);
+ octx->literal >= NFT_LITERAL_ADDR ? 0 : NI_NUMERICHOST);
if (err != 0) {
getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), buf,
sizeof(buf), NULL, 0, NI_NUMERICHOST);
@@ -617,11 +617,11 @@ const struct datatype inet_protocol_type = {
static void inet_service_type_print(const struct expr *expr,
struct output_ctx *octx)
{
- if (octx->numeric >= NFT_NUMERIC_PORT) {
- integer_type_print(expr, octx);
+ if (octx->literal == NFT_LITERAL_PORT) {
+ symbolic_constant_print(&inet_service_tbl, expr, false, octx);
return;
}
- symbolic_constant_print(&inet_service_tbl, expr, false, octx);
+ integer_type_print(expr, octx);
}
static struct error_record *inet_service_type_parse(const struct expr *sym,
diff --git a/src/libnftables.c b/src/libnftables.c
index 9a97a3c5..656b0a1c 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -336,14 +336,14 @@ void nft_ctx_output_set_stateless(struct nft_ctx *ctx, bool val)
ctx->output.stateless = val;
}
-bool nft_ctx_output_get_ip2name(struct nft_ctx *ctx)
+enum nft_literal_level nft_ctx_output_get_literal(struct nft_ctx *ctx)
{
- return ctx->output.ip2name;
+ return ctx->output.literal;
}
-void nft_ctx_output_set_ip2name(struct nft_ctx *ctx, bool val)
+void nft_ctx_output_set_literal(struct nft_ctx *ctx, enum nft_literal_level val)
{
- ctx->output.ip2name = val;
+ ctx->output.literal = val;
}
unsigned int nft_ctx_output_get_debug(struct nft_ctx *ctx)
diff --git a/src/main.c b/src/main.c
index b2966a41..792136f5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,13 +35,14 @@ enum opt_vals {
OPT_NUMERIC = 'n',
OPT_STATELESS = 's',
OPT_IP2NAME = 'N',
+ OPT_LITERAL = 'l',
OPT_DEBUG = 'd',
OPT_HANDLE_OUTPUT = 'a',
OPT_ECHO = 'e',
OPT_INVALID = '?',
};
-#define OPTSTRING "hvcf:iI:jvnsNae"
+#define OPTSTRING "hvcf:iI:jvnsNael"
static const struct option options[] = {
{
@@ -78,6 +79,10 @@ static const struct option options[] = {
.val = OPT_IP2NAME,
},
{
+ .name = "literal",
+ .val = OPT_LITERAL,
+ },
+ {
.name = "includepath",
.val = OPT_INCLUDEPATH,
.has_arg = 1,
@@ -173,6 +178,7 @@ int main(int argc, char * const *argv)
{
char *buf = NULL, *filename = NULL;
enum nft_numeric_level numeric;
+ enum nft_literal_level literal;
bool interactive = false;
unsigned int debug_mask;
unsigned int len;
@@ -224,7 +230,22 @@ int main(int argc, char * const *argv)
nft_ctx_output_set_stateless(nft, true);
break;
case OPT_IP2NAME:
- nft_ctx_output_set_ip2name(nft, true);
+ literal = nft_ctx_output_get_literal(nft);
+ if (literal + 2 > NFT_LITERAL_ADDR) {
+ fprintf(stderr, "Cannot combine `-N' with `-l'\n");
+ exit(EXIT_FAILURE);
+ }
+ nft_ctx_output_set_literal(nft, literal + 2);
+ break;
+ case OPT_LITERAL:
+ literal = nft_ctx_output_get_literal(nft);
+ if (literal + 1 > NFT_LITERAL_ADDR) {
+ fprintf(stderr, "Too many `-l' options or "
+ "perhaps you combined `-l' "
+ "with `-N'?\n");
+ exit(EXIT_FAILURE);
+ }
+ nft_ctx_output_set_literal(nft, literal + 1);
break;
case OPT_DEBUG:
debug_mask = nft_ctx_output_get_debug(nft);