Browse Source
refine local proxy for acl support
refine local proxy for acl support
Max Lv
10 years ago
9 changed files with 135 additions and 53 deletions
Split View
Diff Options
-
18libipset/Makefile
-
2libipset/Makefile.am
-
18libipset/Makefile.in
-
1src/Makefile.am
-
3src/Makefile.in
-
46src/acl.c
-
8src/acl.h
-
91src/local.c
-
1src/local.h
@ -1,7 +1,47 @@ |
|||
#include <ipset/ipset.h> |
|||
#include <utils.h> |
|||
|
|||
struct ip_set *init_acl(void) |
|||
static struct ip_set set; |
|||
|
|||
int init_acl(const char *path) |
|||
{ |
|||
ipset_init_library(); |
|||
ipset_init(&set); |
|||
|
|||
FILE *f = fopen(path, "r"); |
|||
if (f == NULL) FATAL("Invalid acl path."); |
|||
|
|||
char line[256]; |
|||
while(!feof(f)) |
|||
{ |
|||
if (fgets(line, 256, f)) |
|||
{ |
|||
char host[256]; |
|||
int cidr; |
|||
sscanf(line, "%s/%d", host, &cidr); |
|||
struct cork_ipv4 addr; |
|||
int err = cork_ipv4_init(&addr, host); |
|||
if (err) continue; |
|||
ipset_ipv4_add_network(&set, &addr, cidr); |
|||
} |
|||
} |
|||
|
|||
fclose(f); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
void free_acl(void) |
|||
{ |
|||
ipset_done(&set); |
|||
} |
|||
|
|||
int is_bypass(const char* host) |
|||
{ |
|||
struct ip_set *ipset = ipset_new(); |
|||
return ipset; |
|||
struct cork_ipv4 addr; |
|||
int err = cork_ipv4_init(&addr, host); |
|||
if (err) return 0; |
|||
struct cork_ip ip; |
|||
cork_ip_from_ipv4(&ip, &addr); |
|||
return ipset_contains_ip(&set, &ip); |
|||
} |
@ -0,0 +1,8 @@ |
|||
#ifndef _ACL_H |
|||
#define _ACL_H |
|||
|
|||
int init_acl(const char *path); |
|||
void free_acl(void); |
|||
int is_addr_bypass(const char* host); |
|||
|
|||
#endif // _ACL_H |
Write
Preview
Loading…
Cancel
Save