39 const char *message = reason;
43 char *endofflags = strstr(m,
"]");
46 if (m[0] ==
'[' && endofflags)
48 message = strstr(reason,
"]") + 1;
51 const char *token = strtok(m,
"[,");
54 if (!strncmp(token,
"backoff ", strlen(
"backoff ")))
58 msg(
D_PUSH,
"invalid AUTH_FAIL,TEMP flag: %s", token);
62 else if (!strncmp(token,
"advance ", strlen(
"advance ")))
64 token += strlen(
"advance ");
65 if (!strcmp(token,
"no"))
69 else if (!strcmp(token,
"remote"))
74 else if (!strcmp(token,
"addr"))
84 token = strtok(NULL,
"[,");
90 if (!message || message[0] !=
':')
107 long long i = strtoll(str, &endptr, 10);
109 if (
i < INT_MIN || (positive &&
i < 0) || *endptr !=
'\0' ||
i > INT_MAX)
123 long long i = strtoll(str, &endptr, 10);
125 if (
i < 0 || *endptr !=
'\0' ||
i > INT_MAX)
127 msg(msglevel,
"Cannot parse argument '%s' as non-negative integer", str);
138 long long ll = strtoll(str, &endptr, 10);
140 if (ll < 0 || *endptr !=
'\0')
142 msg(msglevel,
"%s: Cannot parse '%s' as non-negative integer", name, str);
146 *value = (int64_t)ll;
154 long long i = strtoll(str, &endptr, 10);
156 if (
i < INT_MIN || *endptr !=
'\0' ||
i > INT_MAX)
158 msg(msglevel,
"Cannot parse argument '%s' as integer", str);
165#if defined(__GNUC__) || defined(__clang__)
166#pragma GCC diagnostic push
167#pragma GCC diagnostic ignored "-Wconversion"
176 long long i = strtoll(str, &endptr, 10);
177 if (
i < INT_MIN || *endptr !=
'\0' ||
i > INT_MAX)
179 msg(msglevel,
"%s: Cannot parse '%s' as integer", name, str);
182 if (i < min || i > max)
186 msg(msglevel,
"%s: Must be an integer >= %d, not %lld",
191 msg(msglevel,
"%s: Must be an integer between %d and %d, not %lld",
201#if defined(__GNUC__) || defined(__clang__)
202#pragma GCC diagnostic pop
206 "dhcp-option",
"dns",
207 "ifconfig",
"ifconfig-ipv6",
208 "push-continuation",
"redirect-gateway",
209 "redirect-private",
"route",
210 "route-gateway",
"route-ipv6",
211 "route-metric",
"topology",
212 "tun-mtu",
"keepalive" };
218 bool opt_is_updatable =
false;
235 if (!(line)[*
i + 1] || (line)[*
i + 1] ==
'-')
243 size_t len = strlen(&line[*
i]);
245 for (
int j = 0; j < count; ++j)
253 && (!line[*
i + opt_len] || line[*
i + opt_len] ==
' '))
255 opt_is_updatable =
true;
260 if (!opt_is_updatable)
264 msg(
D_PUSH,
"Pushed dispensable option is not updatable: '%s'. Ignoring.", line);
268 msg(
M_WARN,
"Pushed option is not updatable: '%s'.", line);
288 if (f->type ==
PUF_TYPE_ACCEPT && strncmp(line, f->pattern, f->size) == 0)
290 msg(
D_LOW,
"Pushed option accepted by filter: '%s'", line);
293 else if (f->type ==
PUF_TYPE_IGNORE && strncmp(line, f->pattern, f->size) == 0)
295 msg(
D_PUSH,
"Pushed option removed by filter: '%s'", line);
299 else if (f->type ==
PUF_TYPE_REJECT && strncmp(line, f->pattern, f->size) == 0)
301 msg(
M_WARN,
"Pushed option rejected by filter: '%s'.", line);
char * string_alloc(const char *str, struct gc_arena *gc)
static void gc_free(struct gc_arena *a)
static struct gc_arena gc_new(void)
#define PUF_TYPE_ACCEPT
filter type to accept a matching option
#define PUF_TYPE_IGNORE
filter type to ignore a matching option
#define PUF_TYPE_REJECT
filter type to reject and trigger SIGUSR1
bool check_push_update_option_flags(char *line, int *i, unsigned int *flags)
Checks the formatting and validity of options inside push-update messages.
static const char * updatable_options[]
int atoi_warn(const char *str, msglvl_t msglevel)
Converts a str to an integer if the string can be represented as an integer number.
int positive_atoi(const char *str, msglvl_t msglevel)
Converts a str to a positive number if the string represents a postive integer number.
bool positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel)
Converts a str to an integer if the string can be represented as an integer number and is >= 0.
bool apply_pull_filter(const struct options *o, char *line)
Filter an option line by all pull filters.
const char * parse_auth_failed_temp(struct options *o, const char *reason)
bool valid_integer(const char *str, bool positive)
Checks if the string is a valid integer by checking if it can be converted to an integer.
bool atoi_constrained(const char *str, int *value, const char *name, int min, int max, msglvl_t msglevel)
Converts a str to an integer if the string can be represented as an integer number and is between min...
#define PUSH_OPT_TO_REMOVE
#define PUSH_OPT_OPTIONAL
Garbage collection arena used to keep track of dynamically allocated memory.
struct pull_filter_list * pull_filter_list
struct pull_filter * head