Przeglądaj źródła

added blacklist to stats export

tags/v1.1.0
root 5 lat temu
rodzic
commit
d114fc8b3f
6 zmienionych plików z 44 dodań i 20 usunięć
  1. 4
    0
      src/dp_blacklist.c
  2. 1
    0
      src/dp_blacklist.h
  3. 4
    3
      src/dp_dhcpv4.c
  4. 23
    17
      src/dp_events.c
  5. 11
    0
      src/dp_helpers.c
  6. 1
    0
      src/dp_helpers.h

+ 4
- 0
src/dp_blacklist.c Wyświetl plik

static dp_blacklist *blacklists = NULL; static dp_blacklist *blacklists = NULL;
static time_t dp_cleanuptime = 0; static time_t dp_cleanuptime = 0;


dp_blacklist *dp_blacklist_get(void) {
return blacklists;
}

void dp_blacklist_add(dp_conf *conf, unsigned char *remoteid, int len) { void dp_blacklist_add(dp_conf *conf, unsigned char *remoteid, int len) {
dp_blacklist *bl; dp_blacklist *bl;



+ 1
- 0
src/dp_blacklist.h Wyświetl plik

UT_hash_handle hh; UT_hash_handle hh;
} dp_blacklist; } dp_blacklist;


dp_blacklist *dp_blacklist_get(void);
void dp_blacklist_add (dp_conf*, unsigned char *, int); void dp_blacklist_add (dp_conf*, unsigned char *, int);
int dp_blacklist_check (dp_conf*, unsigned char *, int); int dp_blacklist_check (dp_conf*, unsigned char *, int);
void dp_blacklist_cleanup (dp_conf*); void dp_blacklist_cleanup (dp_conf*);

+ 4
- 3
src/dp_dhcpv4.c Wyświetl plik





// parse TLV options // parse TLV options
while(offset<pktlen && remoteidlen==0) {
while(offset<pktlen) {
uint8_t type = pkt[offset]; uint8_t type = pkt[offset];
uint8_t len; uint8_t len;


break; break;


// option 53 message type // option 53 message type
if ( type == 53 && len == 1 )
dp_dhcpv4_cnt(*(uint8_t*)(pkt+offset+1));
if ( type == 53 && len == 1 ) {
dp_dhcpv4_cnt((uint8_t)pkt[offset]);
}


// option 82 parser // option 82 parser
if ( type == 82 ) { if ( type == 82 ) {

+ 23
- 17
src/dp_events.c Wyświetl plik

char tmpfile[PATH_MAX+4]; char tmpfile[PATH_MAX+4];
dp_dhcpv4_stats *stats4; dp_dhcpv4_stats *stats4;
dp_dhcpv6_stats *stats6; dp_dhcpv6_stats *stats6;
dp_blacklist *blacklists, *bl, *tmp;
FILE *fh; FILE *fh;
int i; int i;
int first = 1;


snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", conf->stats_file); snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", conf->stats_file);


fprintf(fh,"{ \"dhcpv4\": { "); fprintf(fh,"{ \"dhcpv4\": { ");


for(i=0; i<DP_DHCPV4_CODE_LEN; i++) { for(i=0; i<DP_DHCPV4_CODE_LEN; i++) {
if ( stats4->relcnt[i]>0 ) {
if ( stats4->relcnt[i]>0 || stats4->abscnt[i]>0 ) {
if ( !first ) fprintf(fh, ", ");
fprintf(fh, "\"%s\": { ", dp_dhcpv4_code[i]); fprintf(fh, "\"%s\": { ", dp_dhcpv4_code[i]);
fprintf(fh, "\"rel\": %llu, \"abs\": %llu }", stats4->relcnt[i], stats4->abscnt[i]); fprintf(fh, "\"rel\": %llu, \"abs\": %llu }", stats4->relcnt[i], stats4->abscnt[i]);
first=0;
} }
else if ( stats4->abscnt[i]>0 ) {
fprintf(fh, "\"%s\": { ", dp_dhcpv4_code[i]);
fprintf(fh, "\"abs\": %llu }", stats4->abscnt[i]);
}

if ( ( stats4->relcnt[i]>0 || stats4->abscnt[i]>0 ) && i+1 != DP_DHCPV4_CODE_LEN )
fprintf(fh, ", ");


stats4->relcnt[i]=0; stats4->relcnt[i]=0;
} }


first=1;

stats6 = dp_dhcpv6_cnt(0); stats6 = dp_dhcpv6_cnt(0);


fprintf(fh, "}, \"dhcpv6\" : { "); fprintf(fh, "}, \"dhcpv6\" : { ");


for(i=0; i<DP_DHCPV6_CODE_LEN; i++) { for(i=0; i<DP_DHCPV6_CODE_LEN; i++) {
if ( stats6->relcnt[i]>0 ) {
if ( stats6->relcnt[i]>0 || stats6->abscnt[i]>0 ) {
if ( !first ) fprintf(fh, ", ");
fprintf(fh, "\"%s\": { ", dp_dhcpv6_code[i]); fprintf(fh, "\"%s\": { ", dp_dhcpv6_code[i]);
fprintf(fh, "\"rel\": %llu, \"abs\": %llu }", stats6->relcnt[i], stats6->abscnt[i]); fprintf(fh, "\"rel\": %llu, \"abs\": %llu }", stats6->relcnt[i], stats6->abscnt[i]);
}
else if ( stats6->abscnt[i]>0 ) {
fprintf(fh, "\"%s\": { ", dp_dhcpv6_code[i]);
fprintf(fh, "\"abs\": %llu }", stats6->abscnt[i]);
first=0;
} }


if ( ( stats6->relcnt[i]>0 || stats6->abscnt[i]>0 ) && i+1 != DP_DHCPV6_CODE_LEN )
fprintf(fh, ", ");

stats6->relcnt[i]=0; stats6->relcnt[i]=0;
} }




fprintf(fh, "} }");
fprintf(fh, "}, \"blacklist\": [");

blacklists = dp_blacklist_get();

first=1;
HASH_ITER(hh, blacklists, bl, tmp) {
if ( bl->expire > time(NULL) ) {
if ( !first ) fprintf(fh, ", ");
fprintf(fh, "{ \"id\": \"%s\", \"expire\": %i }", dp_printid(bl->remoteid, bl->len), (int)(bl->expire - time(NULL)));
}
}

fprintf(fh, "] }\n");


fclose(fh); fclose(fh);



+ 11
- 0
src/dp_helpers.c Wyświetl plik



return conf; return conf;
} }

char *dp_printid(unsigned char *str, int len) {
static char hex[1024];
int i;

memset(hex, 0, sizeof(hex));
for(i=0; i<len && i<512; i++) {
sprintf(hex+(i*2),"%02x", str[i]);
}
return hex;
}

+ 1
- 0
src/dp_helpers.h Wyświetl plik

void dp_usage (char*); void dp_usage (char*);
dp_conf *dp_load_config (dp_conf*, char*); dp_conf *dp_load_config (dp_conf*, char*);
void dp_log (unsigned char *, int, char *, ...); void dp_log (unsigned char *, int, char *, ...);
char *dp_printid(unsigned char*, int);


#endif // __DP_MACRO #endif // __DP_MACRO

Ładowanie…
Anuluj
Zapisz