Commit 7871f7db authored by Vadim Kochan's avatar Vadim Kochan Committed by Stephen Hemminger

ss: Allow to specify sport/dport without ':'

Ugly change but it allows to specify sport/dport w/o ':'

    # ss dport = 80 and sport = 44862
Signed-off-by: default avatarVadim Kochan <vadim4j@gmail.com>
parent ee9b3477
...@@ -1380,7 +1380,7 @@ static int xll_name_to_index(const char *dev) ...@@ -1380,7 +1380,7 @@ static int xll_name_to_index(const char *dev)
return ll_name_to_index(dev); return ll_name_to_index(dev);
} }
void *parse_hostcond(char *addr) void *parse_hostcond(char *addr, bool is_port)
{ {
char *port = NULL; char *port = NULL;
struct aafilter a = { .port = -1 }; struct aafilter a = { .port = -1 };
...@@ -1473,10 +1473,14 @@ void *parse_hostcond(char *addr) ...@@ -1473,10 +1473,14 @@ void *parse_hostcond(char *addr)
} else { } else {
port = strrchr(strchr(addr, '/') ? : addr, ':'); port = strrchr(strchr(addr, '/') ? : addr, ':');
} }
if (is_port)
port = addr;
if (port && *port) { if (port && *port) {
if (*port != ':') if (*port == ':')
return NULL; *port++ = 0;
*port++ = 0;
if (*port && *port != '*') { if (*port && *port != '*') {
if (get_integer(&a.port, port, 0)) { if (get_integer(&a.port, port, 0)) {
struct servent *se1 = NULL; struct servent *se1 = NULL;
...@@ -1517,7 +1521,7 @@ void *parse_hostcond(char *addr) ...@@ -1517,7 +1521,7 @@ void *parse_hostcond(char *addr)
} }
} }
} }
if (addr && *addr && *addr != '*') { if (!is_port && addr && *addr && *addr != '*') {
if (get_prefix_1(&a.addr, addr, fam)) { if (get_prefix_1(&a.addr, addr, fam)) {
if (get_dns_host(&a, addr, fam)) { if (get_dns_host(&a, addr, fam)) {
fprintf(stderr, "Error: an inet prefix is expected rather than \"%s\".\n", addr); fprintf(stderr, "Error: an inet prefix is expected rather than \"%s\".\n", addr);
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#define SSF_S_LE 8 #define SSF_S_LE 8
#define SSF_S_AUTO 9 #define SSF_S_AUTO 9
#include <stdbool.h>
struct ssfilter struct ssfilter
{ {
int type; int type;
...@@ -17,5 +19,5 @@ struct ssfilter ...@@ -17,5 +19,5 @@ struct ssfilter
}; };
int ssfilter_parse(struct ssfilter **f, int argc, char **argv, FILE *fp); int ssfilter_parse(struct ssfilter **f, int argc, char **argv, FILE *fp);
void *parse_hostcond(char*); void *parse_hostcond(char *addr, bool is_port);
...@@ -25,6 +25,7 @@ static char **yy_argv; ...@@ -25,6 +25,7 @@ static char **yy_argv;
static int yy_argc; static int yy_argc;
static FILE *yy_fp; static FILE *yy_fp;
static ssfilter_t *yy_ret; static ssfilter_t *yy_ret;
static int tok_type = -1;
static int yylex(void); static int yylex(void);
...@@ -220,14 +221,22 @@ int yylex(void) ...@@ -220,14 +221,22 @@ int yylex(void)
return '('; return '(';
if (strcmp(curtok, ")") == 0) if (strcmp(curtok, ")") == 0)
return ')'; return ')';
if (strcmp(curtok, "dst") == 0) if (strcmp(curtok, "dst") == 0) {
tok_type = DCOND;
return DCOND; return DCOND;
if (strcmp(curtok, "src") == 0) }
if (strcmp(curtok, "src") == 0) {
tok_type = SCOND;
return SCOND; return SCOND;
if (strcmp(curtok, "dport") == 0) }
if (strcmp(curtok, "dport") == 0) {
tok_type = DPORT;
return DPORT; return DPORT;
if (strcmp(curtok, "sport") == 0) }
if (strcmp(curtok, "sport") == 0) {
tok_type = SPORT;
return SPORT; return SPORT;
}
if (strcmp(curtok, ">=") == 0 || if (strcmp(curtok, ">=") == 0 ||
strcmp(curtok, "ge") == 0 || strcmp(curtok, "ge") == 0 ||
strcmp(curtok, "geq") == 0) strcmp(curtok, "geq") == 0)
...@@ -250,9 +259,11 @@ int yylex(void) ...@@ -250,9 +259,11 @@ int yylex(void)
if (strcmp(curtok, "<") == 0 || if (strcmp(curtok, "<") == 0 ||
strcmp(curtok, "lt") == 0) strcmp(curtok, "lt") == 0)
return '<'; return '<';
if (strcmp(curtok, "autobound") == 0) if (strcmp(curtok, "autobound") == 0) {
tok_type = AUTOBOUND;
return AUTOBOUND; return AUTOBOUND;
yylval = (void*)parse_hostcond(curtok); }
yylval = (void*)parse_hostcond(curtok, tok_type == SPORT || tok_type == DPORT);
if (yylval == NULL) { if (yylval == NULL) {
fprintf(stderr, "Cannot parse dst/src address.\n"); fprintf(stderr, "Cannot parse dst/src address.\n");
exit(1); exit(1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment