Skip to content

Commit

Permalink
nfqws,tpws: remove unneeded code
Browse files Browse the repository at this point in the history
  • Loading branch information
bol-van committed Oct 31, 2024
1 parent 228572a commit 8b4b8c3
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 118 deletions.
47 changes: 0 additions & 47 deletions nfq/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <ctype.h>
#include <sys/stat.h>
#include <libgen.h>
#include <wordexp.h>
#include <stdlib.h>

#include "params.h"

Expand Down Expand Up @@ -505,48 +503,3 @@ bool parse_cidr6(char *s, struct cidr6 *cidr)
if (p) *p=d; // restore char
return b;
}


void free_command_line(char **argv, int argc)
{
int i;
if (argv)
{
for (i = 0; i < argc; i++)
if (argv[i]) free(argv[i]);
free(argv);
}
}

char **split_command_line(const char *cmdline, int *argc)
{
int i;
char **argv = NULL;
wordexp_t p;

*argc=0;

// Note! This expands shell variables.
if (!cmdline || wordexp(cmdline, &p, WRDE_NOCMD))
return NULL;

if (!(argv = malloc(p.we_wordc * sizeof(char *))))
{
wordfree(&p);
return NULL;
}

for (i = 0; i < p.we_wordc; i++)
{
if (!(argv[i] = strdup(p.we_wordv[i])))
{
wordfree(&p);
free_command_line(argv,i);
return NULL;
}
}
*argc=i;

wordfree(&p);
return argv;
}
3 changes: 0 additions & 3 deletions nfq/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,3 @@ static inline const struct in6_addr *mask_from_preflen6(uint8_t preflen)
{
return ip6_mask+preflen;
}

void free_command_line(char **argv, int argc);
char **split_command_line(const char *cmdline, int *argc);
11 changes: 4 additions & 7 deletions nfq/nfqws.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,7 @@ static bool parse_ws_scale_factor(char *s, uint16_t *wsize, uint8_t *wscale)

static void cleanup_args()
{
free_command_line(params.argv,params.argc);
params.argv = NULL;
params.argc = 0;
wordfree(&params.wexp);
}

static void cleanup_params(void)
Expand Down Expand Up @@ -1066,14 +1064,13 @@ int main(int argc, char **argv)
replace_char(buf,'\n',' ');
replace_char(buf,'\r',' ');
replace_char(buf,'\t',' ');
params.argv = split_command_line(buf,&params.argc);
if (!params.argv)
if (wordexp(buf, &params.wexp, WRDE_NOCMD))
{
DLOG_ERR("failed to split command line options from file '%s'\n",argv[1]+1);
exit_clean(1);
}
argv=params.argv;
argc=params.argc;
argv=params.wexp.we_wordv;
argc=params.wexp.we_wordc;
}

const struct option long_options[] = {
Expand Down
4 changes: 2 additions & 2 deletions nfq/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <stdio.h>
#include <time.h>
#include <sys/queue.h>
#include <wordexp.h>

#define TLS_PARTIALS_ENABLE true

Expand Down Expand Up @@ -95,8 +96,7 @@ bool dp_list_have_autohostlist(struct desync_profile_list_head *head);

struct params_s
{
char **argv; // for file based config
int argc;
wordexp_t wexp; // for file based config

enum log_target debug_target;
char debug_logfile[PATH_MAX];
Expand Down
47 changes: 0 additions & 47 deletions tpws/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <ifaddrs.h>
#include <time.h>
#include <sys/stat.h>
#include <wordexp.h>
#include <stdlib.h>

void rtrim(char *s)
{
Expand Down Expand Up @@ -420,48 +418,3 @@ bool parse_cidr6(char *s, struct cidr6 *cidr)
if (p) *p=d; // restore char
return b;
}


void free_command_line(char **argv, int argc)
{
int i;
if (argv)
{
for (i = 0; i < argc; i++)
if (argv[i]) free(argv[i]);
free(argv);
}
}

char **split_command_line(const char *cmdline, int *argc)
{
int i;
char **argv = NULL;
wordexp_t p;

*argc=0;

// Note! This expands shell variables.
if (!cmdline || wordexp(cmdline, &p, WRDE_NOCMD))
return NULL;

if (!(argv = malloc(p.we_wordc * sizeof(char *))))
{
wordfree(&p);
return NULL;
}

for (i = 0; i < p.we_wordc; i++)
{
if (!(argv[i] = strdup(p.we_wordv[i])))
{
wordfree(&p);
free_command_line(argv,i);
return NULL;
}
}
*argc=i;

wordfree(&p);
return argv;
}
3 changes: 0 additions & 3 deletions tpws/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,3 @@ static inline const struct in6_addr *mask_from_preflen6(uint8_t preflen)
{
return ip6_mask+preflen;
}

void free_command_line(char **argv, int argc);
char **split_command_line(const char *cmdline, int *argc);
5 changes: 3 additions & 2 deletions tpws/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <sys/param.h>
#include <sys/queue.h>
#include <time.h>
#include <wordexp.h>

#include "tpws.h"
#include "pools.h"
#include "helpers.h"
Expand Down Expand Up @@ -79,8 +81,7 @@ void dp_list_destroy(struct desync_profile_list_head *head);

struct params_s
{
char **argv; // for file based config
int argc;
wordexp_t wexp; // for file based config

int debug;
enum log_target debug_target;
Expand Down
11 changes: 4 additions & 7 deletions tpws/tpws.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ static void exithelp(void)
}
static void cleanup_args()
{
free_command_line(params.argv,params.argc);
params.argv = NULL;
params.argc = 0;
wordfree(&params.wexp);
}
static void cleanup_params(void)
{
Expand Down Expand Up @@ -423,14 +421,13 @@ void parse_params(int argc, char *argv[])
replace_char(buf,'\n',' ');
replace_char(buf,'\r',' ');
replace_char(buf,'\t',' ');
params.argv = split_command_line(buf,&params.argc);
if (!params.argv)
if (wordexp(buf, &params.wexp, WRDE_NOCMD))
{
DLOG_ERR("failed to split command line options from file '%s'\n",argv[1]+1);
exit_clean(1);
}
argv=params.argv;
argc=params.argc;
argv=params.wexp.we_wordv;
argc=params.wexp.we_wordc;
}

const struct option long_options[] = {
Expand Down

0 comments on commit 8b4b8c3

Please sign in to comment.