Skip to content

Commit

Permalink
feat: add show wildcard domain info
Browse files Browse the repository at this point in the history
Signed-off-by: Dengfeng Liu <[email protected]>
  • Loading branch information
liudf0716 committed Jun 12, 2024
1 parent 871265a commit 06e86cf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/wd_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,38 @@ get_trusted_domains_text(void)
return pstr_to_string(pstr);
}

char *
get_trusted_pan_domains_text(void)
{
pstr_t *pstr = pstr_new();
s_config *config = config_get_config();
t_domain_trusted *domain_trusted = NULL;

pstr_cat(pstr, "\nTrusted wildcard domains:\n");

LOCK_DOMAIN();

for (domain_trusted = config->pan_domains_trusted; domain_trusted != NULL; domain_trusted = domain_trusted->next) {
pstr_append_sprintf(pstr, " %s ", domain_trusted->domain);
t_ip_trusted *ip_trusted = domain_trusted->ips_trusted;
if(ip_trusted != NULL) {
pstr_cat(pstr, "with ip:\n");
for (; ip_trusted != NULL; ip_trusted = ip_trusted->next) {
// convert uip to string
char ip[INET_ADDRSTRLEN] = {0};
inet_ntop(AF_INET, &ip_trusted->uip, ip, INET_ADDRSTRLEN);
pstr_append_sprintf(pstr, " %s\n", ip);
}
} else {
pstr_cat(pstr, "\n");
}
}

UNLOCK_DOMAIN();

return pstr_to_string(pstr);
}

char *
mqtt_get_serialize_maclist(int which)
{
Expand Down
2 changes: 2 additions & 0 deletions src/wd_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ char *mqtt_get_trusted_iplist_text(void);

char *get_trusted_domains_text(void);

char *get_trusted_pan_domains_text(void);

char *get_untrusted_maclist_text(void);

char *get_trusted_maclist_text(void);
Expand Down
9 changes: 8 additions & 1 deletion src/wdctl_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,14 @@ show_trusted_pdomains()
static void
wdctl_show_trusted_pan_domains(struct bufferevent *fd)
{
bufferevent_write(fd, "Yes", 3);
char *status = get_trusted_pan_domains_text();
if (status) {
size_t len = strlen(status);
bufferevent_write(fd, status, len); /* XXX Not handling error because we'd just print the same log line. */
free(status);
} else
bufferevent_write(fd, "No", 2);

}

char *
Expand Down

0 comments on commit 06e86cf

Please sign in to comment.