diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2014-12-01 16:40:04 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2014-12-01 16:40:04 +0300 |
commit | 574912df113888ea19b4811b406612544514d9eb (patch) | |
tree | a7fec6d150d8710b31d4730ef7fab5c4c9ce4417 /accel-pppd | |
parent | 3cc7fd0165e096be25761710b66b44fda9d09190 (diff) | |
parent | e09279c7491a8bd16a25b123e03ddd0cd77b566d (diff) | |
download | accel-ppp-574912df113888ea19b4811b406612544514d9eb.tar.gz accel-ppp-574912df113888ea19b4811b406612544514d9eb.zip |
Merge branch 'master' of ssh://git.code.sf.net/p/accel-ppp/code
Diffstat (limited to 'accel-pppd')
125 files changed, 1428 insertions, 1430 deletions
diff --git a/accel-pppd/auth/auth_chap_md5.c b/accel-pppd/auth/auth_chap_md5.c index 5be8b875..9df39eff 100644 --- a/accel-pppd/auth/auth_chap_md5.c +++ b/accel-pppd/auth/auth_chap_md5.c @@ -147,7 +147,7 @@ static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) if (d->interval.tpd) triton_timer_del(&d->interval); - + if (d->name) _free(d->name); @@ -175,7 +175,7 @@ static void chap_timeout_timer(struct triton_timer_t *t) static void chap_restart_timer(struct triton_timer_t *t) { struct chap_auth_data *d = container_of(t, typeof(*d), interval); - + chap_send_challenge(d, 1); } @@ -201,7 +201,7 @@ static void chap_send_failure(struct chap_auth_data *ad) .hdr.len = htons(sizeof(msg) - 1 - 2), .message = MSG_FAILURE, }; - + if (conf_ppp_verbose) log_ppp_info2("send [CHAP Failure id=%x \"%s\"]\n", msg.hdr.id, MSG_FAILURE); @@ -217,7 +217,7 @@ static void chap_send_success(struct chap_auth_data *ad, int id) .hdr.len = htons(sizeof(msg)-1-2), .message = MSG_SUCCESS, }; - + if (conf_ppp_verbose) log_ppp_info2("send [CHAP Success id=%x \"%s\"]\n", msg.hdr.id, MSG_SUCCESS); @@ -301,7 +301,7 @@ static void chap_recv_response(struct chap_auth_data *ad, struct chap_hdr *hdr) print_str(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); log_ppp_info2("\"]\n"); } - + if (ad->started && msg->hdr.id == ad->id - 1) { chap_send_success(ad, msg->hdr.id); return; @@ -364,7 +364,7 @@ static void chap_recv_response(struct chap_auth_data *ad, struct chap_hdr *hdr) MD5_Update(&md5_ctx,passwd,strlen(passwd)); MD5_Update(&md5_ctx,ad->val,VALUE_SIZE); MD5_Final(md5,&md5_ctx); - + if (memcmp(md5,msg->val,sizeof(md5))) { if (conf_ppp_verbose) @@ -389,7 +389,7 @@ static void chap_recv_response(struct chap_auth_data *ad, struct chap_hdr *hdr) } } else _free(name); - + ad->id++; } _free(passwd); @@ -429,7 +429,7 @@ static int chap_check(uint8_t *ptr) static int chap_restart(struct ppp_t *ppp, struct auth_data_t *auth) { struct chap_auth_data *d = container_of(auth, typeof(*d), auth); - + chap_send_challenge(d, 1); return 0; @@ -491,7 +491,7 @@ static void auth_chap_md5_init() if (ppp_auth_register_handler(&chap)) log_emerg("chap-md5: failed to register handler\n"); - + triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); } diff --git a/accel-pppd/auth/auth_mschap_v1.c b/accel-pppd/auth/auth_mschap_v1.c index d9232cc9..bf78f23e 100644 --- a/accel-pppd/auth/auth_mschap_v1.c +++ b/accel-pppd/auth/auth_mschap_v1.c @@ -176,7 +176,7 @@ static void chap_timeout_timer(struct triton_timer_t *t) static void chap_restart_timer(struct triton_timer_t *t) { struct chap_auth_data *d = container_of(t, typeof(*d), interval); - + chap_send_challenge(d, 1); } @@ -218,7 +218,7 @@ static void chap_send_success(struct chap_auth_data *ad, int id) hdr->id = id; hdr->len = htons(HDR_LEN + strlen(conf_msg_success)); strcpy((char *)(hdr + 1), conf_msg_success); - + if (conf_ppp_verbose) log_ppp_info2("send [MSCHAP-v1 Success id=%x \"%s\"]\n", hdr->id, conf_msg_success); @@ -278,14 +278,14 @@ static void auth_result(struct chap_auth_data *ad, int res) name = NULL; } } - + ad->id++; if (ad->mschap_error != conf_msg_failure) { _free(ad->mschap_error); ad->mschap_error = conf_msg_failure; } - + if (name) _free(name); } @@ -358,7 +358,7 @@ static void chap_recv_response(struct chap_auth_data *ad, struct chap_hdr *hdr) ad->mschap_error = conf_msg_failure; r = pwdb_check(&ad->ppp->ses, (pwdb_callback)auth_result, ad, name, PPP_CHAP, MSCHAP_V1, ad->id, ad->val, VALUE_SIZE, msg->lm_hash, msg->nt_hash, msg->flags, &ad->mschap_error); - + if (r == PWDB_WAIT) { ad->name = name; return; @@ -367,7 +367,7 @@ static void chap_recv_response(struct chap_auth_data *ad, struct chap_hdr *hdr) if (r == PWDB_NO_IMPL) if (chap_check_response(ad, msg, name)) r = PWDB_DENIED; - + if (r == PWDB_DENIED) { chap_send_failure(ad, ad->mschap_error); if (ad->started) @@ -426,7 +426,7 @@ static void des_encrypt(const uint8_t *input, const uint8_t *key, uint8_t *outpu DES_set_key_checked(&cb, &ks); memcpy(cb, input, 8); DES_ecb_encrypt(&cb, &res, &ks, DES_ENCRYPT); - memcpy(output, res, 8); + memcpy(output, res, 8); } static int chap_check_response(struct chap_auth_data *ad, struct chap_response *msg, const char *name) @@ -437,7 +437,7 @@ static int chap_check_response(struct chap_auth_data *ad, struct chap_response * char *passwd; char *u_passwd; int i; - + passwd = pwdb_get_passwd(&ad->ppp->ses, name); if (!passwd) { if (conf_ppp_verbose) @@ -497,7 +497,7 @@ static void set_mppe_keys(struct chap_auth_data *ad, uint8_t *z_hash) SHA1_Update(&sha_ctx, digest, 16); SHA1_Update(&sha_ctx, digest, 16); SHA1_Update(&sha_ctx, ad->val, VALUE_SIZE); - SHA1_Final(digest, &sha_ctx); + SHA1_Final(digest, &sha_ctx); triton_event_fire(EV_MPPE_KEYS, &ev_mppe); } @@ -505,7 +505,7 @@ static void set_mppe_keys(struct chap_auth_data *ad, uint8_t *z_hash) static int chap_restart(struct ppp_t *ppp, struct auth_data_t *auth) { struct chap_auth_data *d = container_of(auth, typeof(*d), auth); - + chap_send_challenge(d, 1); return 0; diff --git a/accel-pppd/auth/auth_mschap_v2.c b/accel-pppd/auth/auth_mschap_v2.c index 0235ddf0..f416c434 100644 --- a/accel-pppd/auth/auth_mschap_v2.c +++ b/accel-pppd/auth/auth_mschap_v2.c @@ -19,7 +19,7 @@ #include "memdebug.h" -#define MSCHAP_V2 0x81 +#define MSCHAP_V2 0x81 #define CHAP_CHALLENGE 1 #define CHAP_RESPONSE 2 @@ -119,7 +119,7 @@ static void auth_data_free(struct ppp_t *ppp, struct auth_data_t *auth) if (d->interval.tpd) triton_timer_del(&d->interval); - + _free(d); } @@ -177,7 +177,7 @@ static void chap_timeout_timer(struct triton_timer_t *t) static void chap_restart_timer(struct triton_timer_t *t) { struct chap_auth_data *d = container_of(t, typeof(*d), interval); - + chap_send_challenge(d, 1); } @@ -203,7 +203,7 @@ static void chap_send_failure(struct chap_auth_data *ad, char *mschap_error, cha hdr->len = htons(HDR_LEN + strlen(mschap_error) + strlen(reply_msg) + 3); sprintf((char *)(hdr + 1), "%s M=%s", mschap_error, reply_msg); - + if (conf_ppp_verbose) log_ppp_info2("send [MSCHAP-v2 Failure id=%x \"%s\"]\n", hdr->id, (char *)(hdr + 1)); @@ -240,7 +240,7 @@ static int generate_response(struct chap_auth_data *ad, struct chap_response *ms uint8_t c_hash[SHA_DIGEST_LENGTH]; uint8_t response[SHA_DIGEST_LENGTH]; int i; - + uint8_t magic1[39] = {0x4D, 0x61, 0x67, 0x69, 0x63, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x74, 0x6F, 0x20, 0x63, 0x6C, 0x69, 0x65, @@ -290,10 +290,10 @@ static int generate_response(struct chap_auth_data *ad, struct chap_response *ms SHA1_Update(&sha_ctx,c_hash,8); SHA1_Update(&sha_ctx,magic2,41); SHA1_Final(response,&sha_ctx); - + for(i=0; i<20; i++) sprintf(authenticator+i*2,"%02X",response[i]); - + _free(passwd); _free(u_passwd); @@ -351,19 +351,19 @@ static void auth_result(struct chap_auth_data *ad, int res) name = NULL; } } - + ad->id++; if (ad->mschap_error != conf_msg_failure) { _free(ad->mschap_error); ad->mschap_error = conf_msg_failure; } - + if (ad->reply_msg != conf_msg_failure2) { _free(ad->reply_msg); ad->reply_msg = conf_msg_failure2; } - + if (name) _free(name); } @@ -398,7 +398,7 @@ static void chap_recv_response(struct chap_auth_data *ad, struct chap_hdr *hdr) if (ad->name) return; - + ad->mschap_error = conf_msg_failure; ad->reply_msg = conf_msg_failure2; @@ -427,7 +427,7 @@ static void chap_recv_response(struct chap_auth_data *ad, struct chap_hdr *hdr) ppp_auth_failed(ad->ppp, NULL); return; } - + r = pwdb_check(&ad->ppp->ses, (pwdb_callback)auth_result, ad, name, PPP_CHAP, MSCHAP_V2, ad->id, ad->val, msg->peer_challenge, msg->reserved, msg->nt_hash, msg->flags, authenticator, &ad->mschap_error, &ad->reply_msg); if (r == PWDB_WAIT) { @@ -449,7 +449,7 @@ static void chap_recv_response(struct chap_auth_data *ad, struct chap_hdr *hdr) ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); else ppp_auth_failed(ad->ppp, name); - + _free(name); if (ad->mschap_error != conf_msg_failure) { @@ -508,7 +508,7 @@ static void des_encrypt(const uint8_t *input, const uint8_t *key, uint8_t *outpu DES_set_key_checked(&cb, &ks); memcpy(cb,input,8); DES_ecb_encrypt(&cb,&res,&ks,DES_ENCRYPT); - memcpy(output,res,8); + memcpy(output,res,8); } static int chap_check_response(struct chap_auth_data *ad, struct chap_response *msg, const char *name) @@ -521,7 +521,7 @@ static int chap_check_response(struct chap_auth_data *ad, struct chap_response * char *passwd; char *u_passwd; int i; - + passwd = pwdb_get_passwd(&ad->ppp->ses, name); if (!passwd) { if (conf_ppp_verbose) @@ -566,7 +566,7 @@ static void set_mppe_keys(struct chap_auth_data *ad, uint8_t *z_hash, uint8_t *n uint8_t digest[20]; uint8_t send_key[20]; uint8_t recv_key[20]; - + uint8_t pad1[40] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -612,7 +612,7 @@ static void set_mppe_keys(struct chap_auth_data *ad, uint8_t *z_hash, uint8_t *n .recv_key = recv_key, .send_key = send_key, }; - + //NtPasswordHashHash MD4_Init(&md4_ctx); MD4_Update(&md4_ctx, z_hash, 16); @@ -652,7 +652,7 @@ static int chap_check(uint8_t *ptr) static int chap_restart(struct ppp_t *ppp, struct auth_data_t *auth) { struct chap_auth_data *d = container_of(auth, typeof(*d), auth); - + chap_send_challenge(d, 1); return 0; diff --git a/accel-pppd/auth/auth_pap.c b/accel-pppd/auth/auth_pap.c index 909b115e..15154bf8 100644 --- a/accel-pppd/auth/auth_pap.c +++ b/accel-pppd/auth/auth_pap.c @@ -105,10 +105,10 @@ static int pap_start(struct ppp_t *ppp, struct auth_data_t *auth) static int pap_finish(struct ppp_t *ppp, struct auth_data_t *auth) { struct pap_auth_data *d = container_of(auth, typeof(*d), auth); - + if (d->timeout.tpd) triton_timer_del(&d->timeout); - + if (d->peer_id) _free(d->peer_id); @@ -147,10 +147,10 @@ static void pap_send_ack(struct pap_auth_data *p, int id) msg->hdr.len = htons(HDR_LEN + 1 + sizeof(MSG_SUCCESSED) - 1); msg->msg_len = sizeof(MSG_SUCCESSED) - 1; memcpy(msg->msg, MSG_SUCCESSED, sizeof(MSG_SUCCESSED)); - + if (conf_ppp_verbose) log_ppp_info2("send [PAP AuthAck id=%x \"%s\"]\n", id, MSG_SUCCESSED); - + ppp_chan_send(p->ppp, msg, ntohs(msg->hdr.len) + 2); } @@ -164,10 +164,10 @@ static void pap_send_nak(struct pap_auth_data *p, int id) msg->hdr.len = htons(HDR_LEN + 1 + sizeof(MSG_FAILED) - 1); msg->msg_len = sizeof(MSG_FAILED) - 1; memcpy(msg->msg, MSG_FAILED, sizeof(MSG_FAILED)); - + if (conf_ppp_verbose) log_ppp_info2("send [PAP AuthNak id=%x \"%s\"]\n", id, MSG_FAILED); - + ppp_chan_send(p->ppp, msg, ntohs(msg->hdr.len) + 2); } @@ -236,7 +236,7 @@ static int pap_recv_req(struct pap_auth_data *p, struct pap_hdr *hdr) } peer_id = _strndup((const char*)peer_id, peer_id_len); - + if (conf_any_login) { if (ppp_auth_succeeded(p->ppp, peer_id)) { pap_send_nak(p, hdr->id); @@ -293,17 +293,17 @@ static int pap_recv_req(struct pap_auth_data *p, struct pap_hdr *hdr) _free(passwd); return ret; - + failed: pap_send_nak(p, hdr->id); if (p->started) ap_session_terminate(&p->ppp->ses, TERM_AUTH_ERROR, 0); else ppp_auth_failed(p->ppp, peer_id); - + _free(passwd); _free(peer_id); - + return -1; } diff --git a/accel-pppd/backup/backup.c b/accel-pppd/backup/backup.c index 16349fc7..18e9332f 100644 --- a/accel-pppd/backup/backup.c +++ b/accel-pppd/backup/backup.c @@ -15,7 +15,7 @@ static LIST_HEAD(module_list); struct backup_tag __export *backup_add_tag(struct backup_mod *m, uint8_t id, int internal, const void *data, size_t size) { struct backup_tag *t; - + t = m->data->storage->alloc_tag(m->data, size); if (!t) return NULL; @@ -39,7 +39,7 @@ void backup_add_fd(struct backup_mod *m, int fd) struct backup_mod __export *backup_find_mod(struct backup_data *d, uint8_t mod_id) { struct backup_mod *m; - + list_for_each_entry(m, &d->mod_list, entry) { if (m->id == mod_id) return m; @@ -232,19 +232,19 @@ void __export backup_register_storage(struct backup_storage *s) void backup_restore_fd() { - + } void backup_restore(int internal) { struct backup_storage *storage; struct backup_module *module; - + list_for_each_entry(storage, &storage_list, entry) { if (storage->restore) storage->restore(internal); } - + list_for_each_entry(module, &module_list, entry) { if (module->restore_complete) module->restore_complete(); diff --git a/accel-pppd/backup/backup.h b/accel-pppd/backup/backup.h index 0037596a..3d3d77ec 100644 --- a/accel-pppd/backup/backup.h +++ b/accel-pppd/backup/backup.h @@ -41,7 +41,7 @@ struct backup_data struct list_head mod_list; int internal:1; }; - + struct backup_module { struct list_head entry; @@ -49,7 +49,7 @@ struct backup_module int (*save)(struct ap_session *, struct backup_mod *); int (*restore)(struct ap_session *, struct backup_mod *); - + struct ap_session *(*ctrl_restore)(struct backup_mod *); void (*ctrl_start)(struct ap_session *ses); void (*restore_complete)(void); @@ -61,18 +61,18 @@ struct backup_storage /*int (*check_integrity)(void); int (*restore)(int internal);*/ - + void (*restore)(int internal); struct backup_data *(*create)(struct ap_session *); int (*commit)(struct backup_data *); void (*free)(struct backup_data *); - + struct backup_mod *(*alloc_mod)(struct backup_data *); void (*free_mod)(struct backup_mod *); void (*add_fd)(struct backup_data *, int fd); - + struct backup_tag *(*alloc_tag)(struct backup_data *, int size); void (*free_tag)(struct backup_data *, struct backup_tag *); }; diff --git a/accel-pppd/backup/backup_file.c b/accel-pppd/backup/backup_file.c index b9d26466..06dc02d4 100644 --- a/accel-pppd/backup/backup_file.c +++ b/accel-pppd/backup/backup_file.c @@ -78,7 +78,7 @@ static int fs_commit(struct backup_data *d) MD5_Init(&md5); MD5_Update(&md5, &version, 1); - + iov[0].iov_base = &version; iov[0].iov_len = 1; i = 1; @@ -145,7 +145,7 @@ static int fs_commit(struct backup_data *d) } return 0; - + out_err: close(fd); unlink(fname); @@ -159,10 +159,10 @@ static void fs_free(struct backup_data *d) if (fsd->map_addr) munmap(fsd->map_addr, fsd->map_len); - + if (fsd->fd != -1) close(fsd->fd); - + sprintf(fname, "%s/%s", conf_path, d->ses->sessionid); unlink(fname); @@ -190,10 +190,10 @@ static void fs_free_mod(struct backup_mod *mod) static struct backup_tag *fs_alloc_tag(struct backup_data *d, int size) { struct backup_tag *t = _malloc(sizeof(struct backup_tag) + 4 + size); - + if (!t) return NULL; - + memset(t, 0, sizeof(*t)); t->data = (uint8_t *)(t + 1) + 4; @@ -240,7 +240,7 @@ static void restore_session(const char *fn, int internal) close(fd); return; } - + if (*ptr != VERSION) goto out; @@ -250,11 +250,11 @@ static void restore_session(const char *fn, int internal) if (memcmp(md5_buf, ptr + st.st_size - 16, 16)) goto out; - + d = fs_create(NULL); if (!d) goto out; - + d->internal = internal; fsd = container_of(d, typeof(*fsd), data); @@ -304,10 +304,10 @@ static void fs_restore(int internal) { DIR *dirp; struct dirent ent, *res; - + if (!conf_path) return; - + dirp = opendir(conf_path); if (!dirp) { log_emerg("backup_file: opendir: %s\n", strerror(errno)); diff --git a/accel-pppd/cli/cli.c b/accel-pppd/cli/cli.c index 8b5f5165..7d440727 100644 --- a/accel-pppd/cli/cli.c +++ b/accel-pppd/cli/cli.c @@ -49,7 +49,7 @@ void __export cli_register_simple_cmd2( c = malloc(sizeof(*c)); memset(c, 0, sizeof(*c)); - + c->exec = exec; c->help = help; c->hdr_len = hdr_len; @@ -57,7 +57,7 @@ void __export cli_register_simple_cmd2( for (i = 0; i < hdr_len; i++) c->hdr[i] = va_arg(ap, char *); - + list_add_tail(&c->entry, &simple_cmd_list); va_end(ap); @@ -319,7 +319,7 @@ out_found: static void load_config(void) { const char *opt; - + if (conf_cli_passwd) _free(conf_cli_passwd); opt = conf_get_opt("cli", "password"); @@ -327,7 +327,7 @@ static void load_config(void) conf_cli_passwd = _strdup(opt); else conf_cli_passwd = NULL; - + if (conf_cli_prompt && conf_cli_prompt != def_cli_prompt) _free(conf_cli_prompt); opt = conf_get_opt("cli", "prompt"); diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c index 84ccb70b..6a6732b3 100644 --- a/accel-pppd/cli/show_sessions.c +++ b/accel-pppd/cli/show_sessions.c @@ -103,7 +103,7 @@ static void free_row(struct row_t *row) static void insert_row(struct list_head *list, struct row_t *row) { struct row_t *row2, *row3; - + row3 = NULL; list_for_each_entry(row2, list, entry) { if (strcmp(row->order_key, row2->order_key) <= 0) { @@ -213,7 +213,7 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli) col->hidden = 1; list_add_tail(&col->entry, &c_list); } - + if (order_key && !order_key_f) { col = _malloc(sizeof(*col)); col->column = order_key; diff --git a/accel-pppd/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c index 84a7711c..38e6a8b6 100644 --- a/accel-pppd/cli/std_cmd.c +++ b/accel-pppd/cli/std_cmd.c @@ -113,7 +113,7 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli) pcre *re; const char *pcre_err; int pcre_offset; - + if (f_cnt == 5) { if (!strcmp(f[4], "hard")) hard = 1; @@ -121,7 +121,7 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli) return CLI_CMD_SYNTAX; } else if (f_cnt != 4) return CLI_CMD_SYNTAX; - + re = pcre_compile2(f[3], 0, NULL, &pcre_err, &pcre_offset, NULL); if (!re) { cli_sendv(cli, "match: %s at %i\r\n", pcre_err, pcre_offset); @@ -140,9 +140,9 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli) triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_soft, ses); } pthread_rwlock_unlock(&ses_lock); - + pcre_free(re); - + return CLI_CMD_OK; } @@ -151,7 +151,7 @@ static int terminate_exec2(int key, char * const *f, int f_cnt, void *cli) struct ap_session *ses; int hard = 0; in_addr_t ipaddr = 0; - + if (f_cnt == 4) { if (!strcmp(f[3], "hard")) hard = 1; @@ -159,10 +159,10 @@ static int terminate_exec2(int key, char * const *f, int f_cnt, void *cli) return CLI_CMD_SYNTAX; } else if (f_cnt != 3) return CLI_CMD_SYNTAX; - + if (key == 1) ipaddr = inet_addr(f[2]); - + pthread_rwlock_rdlock(&ses_lock); list_for_each_entry(ses, &ses_list, entry) { switch (key) { @@ -205,7 +205,7 @@ static int terminate_exec(const char *cmd, char * const *fields, int fields_cnt, if (fields_cnt == 1) return CLI_CMD_SYNTAX; - + if (!strcmp(fields[1], "match") && fields_cnt > 3 && !strcmp(fields[2], "username")) return terminate_exec1(fields, fields_cnt, client); else if (!strcmp(fields[1], "username")) @@ -220,7 +220,7 @@ static int terminate_exec(const char *cmd, char * const *fields, int fields_cnt, return terminate_exec2(4, fields, fields_cnt, client); else if (strcmp(fields[1], "all")) return CLI_CMD_SYNTAX; - + if (fields_cnt == 3) { if (!strcmp(fields[2], "hard")) hard = 1; @@ -228,7 +228,7 @@ static int terminate_exec(const char *cmd, char * const *fields, int fields_cnt, return CLI_CMD_SYNTAX; } else if (fields_cnt != 2) return CLI_CMD_SYNTAX; - + pthread_rwlock_rdlock(&ses_lock); list_for_each_entry(ses, &ses_list, entry) { if (hard) diff --git a/accel-pppd/cli/tcp.c b/accel-pppd/cli/tcp.c index 9f60cbf3..2a6bfdee 100644 --- a/accel-pppd/cli/tcp.c +++ b/accel-pppd/cli/tcp.c @@ -94,7 +94,7 @@ static int cli_client_send(struct cli_client_t *tcln, const void *_buf, int size if (cln->disconnect) return -1; - + if (!list_empty(&cln->xmit_queue)) { b = _malloc(sizeof(*b) + size); b->size = size; @@ -197,10 +197,10 @@ static int cln_write(struct triton_md_handler_t *h) { struct tcp_client_t *cln = container_of(h, typeof(*cln), hnd); int k; - + if (!cln->xmit_buf) return 0; - + while (1) { for (; cln->xmit_pos < cln->xmit_buf->size; cln->xmit_pos += k) { k = write(cln->hnd.fd, cln->xmit_buf->buf + cln->xmit_pos, cln->xmit_buf->size - cln->xmit_pos); @@ -312,7 +312,7 @@ static void start_server(const char *host, int port) log_emerg("cli: tcp: failed to create server socket: %s\n", strerror(errno)); return; } - + fcntl(serv_hnd.fd, F_SETFD, fcntl(serv_hnd.fd, F_GETFD) | FD_CLOEXEC); memset(&addr, 0, sizeof(addr)); @@ -323,7 +323,7 @@ static void start_server(const char *host, int port) else addr.sin_addr.s_addr = htonl(INADDR_ANY); - setsockopt(serv_hnd.fd, SOL_SOCKET, SO_REUSEADDR, &serv_hnd.fd, 4); + setsockopt(serv_hnd.fd, SOL_SOCKET, SO_REUSEADDR, &serv_hnd.fd, 4); if (bind (serv_hnd.fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) { log_emerg("cli: tcp: failed to bind socket: %s\n", strerror(errno)); close(serv_hnd.fd); @@ -341,7 +341,7 @@ static void start_server(const char *host, int port) close(serv_hnd.fd); return; } - + addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = inet_addr(host); @@ -383,15 +383,15 @@ static void init(void) port = atoi(d + 1); if (port <= 0) goto err_fmt; - + load_config(); temp_buf = malloc(RECV_BUF_SIZE); start_server(host, port); - + triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); - + return; err_fmt: log_emerg("cli: tcp: invalid format\n"); diff --git a/accel-pppd/cli/telnet.c b/accel-pppd/cli/telnet.c index cece88ee..de2f39ff 100644 --- a/accel-pppd/cli/telnet.c +++ b/accel-pppd/cli/telnet.c @@ -142,7 +142,7 @@ static int telnet_send(struct telnet_client_t *cln, const void *_buf, int size) if (cln->disconnect) return -1; - + if (!list_empty(&cln->xmit_queue)) { b = _malloc(sizeof(*b) + size); b->size = size; @@ -212,10 +212,10 @@ static int send_password_request(struct telnet_client_t *cln) if (telnet_send(cln, buf0, sizeof(buf0))) return -1; - + if (telnet_send(cln, buf1, sizeof(buf1))) return -1; - + return 0; } @@ -240,10 +240,10 @@ static int send_cmdline_tail(struct telnet_client_t *cln, int corr) return -1; memset(temp_buf, '\b', cln->cmdline_len - cln->cmdline_pos - corr); - + if (telnet_send(cln, temp_buf, cln->cmdline_len - cln->cmdline_pos - corr)) return -1; - + return 0; } @@ -276,7 +276,7 @@ static int telnet_input_char(struct telnet_client_t *cln, uint8_t c) if (c == '\n') return 0; - + if (c == '\r') { cln->cmdline[cln->cmdline_len] = 0; @@ -304,14 +304,14 @@ static int telnet_input_char(struct telnet_client_t *cln, uint8_t c) b->size = cln->cmdline_len; list_add(&b->entry, cln->history.next); cln->history_pos = cln->history.next; - + if (conf_verbose == 2) log_info2("cli: %s: %s\n", inet_ntoa(cln->addr.sin_addr), cln->cmdline); if (cli_process_cmd(&cln->cli_client)) return -1; } - + cln->cmdline_pos = 0; cln->cmdline_len = 0; @@ -346,7 +346,7 @@ static int telnet_input_char(struct telnet_client_t *cln, uint8_t c) if (c != SE) return 0; } - + cln->telcmd = 0; } else if (cln->esc) { if (cln->cmdline_pos2 == RECV_BUF_SIZE - 1) { @@ -360,7 +360,7 @@ static int telnet_input_char(struct telnet_client_t *cln, uint8_t c) if (cln->cmdline_pos2 - cln->cmdline_len != 2) return 0; - + cln->esc = 0; if (cln->auth) { @@ -413,14 +413,14 @@ static int telnet_input_char(struct telnet_client_t *cln, uint8_t c) if (cln->cmdline_pos) { if (cln->cmdline_pos < cln->cmdline_len) { memmove(cln->cmdline + cln->cmdline_pos - 1, cln->cmdline + cln->cmdline_pos, cln->cmdline_len - cln->cmdline_pos); - + cln->cmdline[cln->cmdline_len - 1] = ' '; - + if (telnet_send(cln, "\b", 1)) return -1; - + cln->cmdline_pos--; - + if (send_cmdline_tail(cln, 0)) return -1; } else { @@ -459,7 +459,7 @@ static int telnet_input_char(struct telnet_client_t *cln, uint8_t c) return -1; } } - + if (cln->cmdline_pos < cln->cmdline_len) { if (send_cmdline_tail(cln, 0)) return -1; @@ -585,9 +585,9 @@ static int serv_read(struct triton_md_handler_t *h) list_add(&b2->entry, conn->history.next); } pthread_mutex_unlock(&history_lock); - + conn->history_pos = conn->history.next; - + conn->cli_client.cmdline = conn->cmdline; conn->cli_client.send = cli_client_send; conn->cli_client.sendv = cli_client_sendv; @@ -649,7 +649,7 @@ static void start_server(const char *host, int port) log_emerg("cli: telnet: failed to create server socket: %s\n", strerror(errno)); return; } - + fcntl(serv_hnd.fd, F_SETFD, fcntl(serv_hnd.fd, F_GETFD) | FD_CLOEXEC); memset(&addr, 0, sizeof(addr)); @@ -660,7 +660,7 @@ static void start_server(const char *host, int port) else addr.sin_addr.s_addr = htonl(INADDR_ANY); - setsockopt(serv_hnd.fd, SOL_SOCKET, SO_REUSEADDR, &serv_hnd.fd, 4); + setsockopt(serv_hnd.fd, SOL_SOCKET, SO_REUSEADDR, &serv_hnd.fd, 4); if (bind (serv_hnd.fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) { log_emerg("cli: telnet: failed to bind socket: %s\n", strerror(errno)); close(serv_hnd.fd); @@ -678,7 +678,7 @@ static void start_server(const char *host, int port) close(serv_hnd.fd); return; } - + addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = inet_addr(host); @@ -715,7 +715,7 @@ static void load_history_file(void) f = fopen(conf_history_file, "r"); if (!f) return; - + while (fgets((char *)temp_buf, RECV_BUF_SIZE, f)) { b = _malloc(sizeof(*b) + strlen((char *)temp_buf) + 1); b->p_buf = NULL; @@ -747,12 +747,12 @@ static void init(void) opt = conf_get_opt("cli", "telnet"); if (!opt) return; - + host = strdup(opt); d = strstr(host, ":"); if (!d) goto err_fmt; - + *d = 0; port = atoi(d + 1); if (port <= 0) @@ -770,11 +770,11 @@ static void init(void) load_history_file(); start_server(host, port); - + atexit(save_history_file); - + triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); - + return; err_fmt: log_emerg("cli: telnet: invalid format\n"); diff --git a/accel-pppd/ctrl/ipoe/arp.c b/accel-pppd/ctrl/ipoe/arp.c index 10ea138f..ebf05c7b 100644 --- a/accel-pppd/ctrl/ipoe/arp.c +++ b/accel-pppd/ctrl/ipoe/arp.c @@ -50,7 +50,7 @@ static int arp_read(struct triton_md_handler_t *h) dst.sll_family = AF_PACKET; dst.sll_ifindex = s->ipoe->ifindex; dst.sll_protocol = htons(ETH_P_ARP); - + ah2.ar_hrd = htons(ARPHRD_ETHER); ah2.ar_pro = htons(ETH_P_IP); ah2.ar_hln = ETH_ALEN; diff --git a/accel-pppd/ctrl/ipoe/backup.c b/accel-pppd/ctrl/ipoe/backup.c index 9633bf71..b272731b 100644 --- a/accel-pppd/ctrl/ipoe/backup.c +++ b/accel-pppd/ctrl/ipoe/backup.c @@ -51,16 +51,16 @@ static int session_save(struct ap_session *ses, struct backup_mod *m) if (conn->ifcfg) flags |= IPOE_FLAG_IFCFG; - + if (conn->dhcp_addr) flags |= IPOE_FLAG_DHCP_ADDR; - + if (conn->relay_addr) flags |= IPOE_FLAG_RELAY_ADDR; - + if (conn->l4_redirect) flags |= IPOE_FLAG_L4_REDIR; - + if (conn->l4_redirect_set) flags |= IPOE_FLAG_L4_REDIR_SET; @@ -82,7 +82,7 @@ static int session_save(struct ap_session *ses, struct backup_mod *m) if (conn->relay_agent) add_tag(IPOE_TAG_RELAY_AGENT, conn->relay_agent->data, conn->relay_agent->len); - + add_tag_i(IPOE_TAG_IFINDEX, &conn->ifindex, 4); return 0; @@ -98,7 +98,7 @@ static int session_restore(struct ap_session *ses, struct backup_mod *m) static void set_dhcpv4_opt(struct dhcpv4_option **opt, struct backup_tag *t, uint8_t **ptr) { - *opt = (struct dhcpv4_option *)(*ptr); + *opt = (struct dhcpv4_option *)(*ptr); (*opt)->len = t->size; memcpy((*opt)->data, t->data, t->size); (*ptr) += sizeof(**opt) + t->size; @@ -200,23 +200,23 @@ static struct ap_session *ctrl_restore(struct backup_mod *m) if (flags & IPOE_FLAG_IFCFG) ses->ifcfg = 1; - + if (flags & IPOE_FLAG_DHCP_ADDR) { dhcpv4_reserve_ip(ses->serv->dhcpv4, ses->yiaddr); ses->dhcp_addr = 1; } - + if (flags & IPOE_FLAG_RELAY_ADDR) ses->relay_addr = 1; - + if (flags & IPOE_FLAG_L4_REDIR) ses->l4_redirect = 1; - + if (flags & IPOE_FLAG_L4_REDIR_SET && m->data->internal) ses->l4_redirect = 1; ses->serv = serv; - + triton_context_register(&ses->ctx, &ses->ses); triton_context_wakeup(&ses->ctx); diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c index 936b50e4..18dea808 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4.c +++ b/accel-pppd/ctrl/ipoe/dhcpv4.c @@ -57,10 +57,10 @@ static int open_raw_sock(void) log_error("dhcpv4: socket(AF_PACKET, SOCK_RAW): %s\n", strerror(errno)); return -1; } - + fcntl(raw_sock, F_SETFL, O_NONBLOCK); fcntl(raw_sock, F_SETFD, fcntl(raw_sock, F_GETFD) | FD_CLOEXEC); - + pthread_setspecific(raw_sock_key, (void *)(long)raw_sock); } @@ -78,7 +78,7 @@ static struct dhcpv4_iprange *parse_range(const char *str) struct dhcpv4_iprange *r; n = sscanf(str, "%u.%u.%u.%u/%u", &f1, &f2, &f3, &f4, &m); - + if (n != 5) goto parse_err; if (f1 > 255) @@ -91,7 +91,7 @@ static struct dhcpv4_iprange *parse_range(const char *str) goto parse_err; if (m == 0 || m > 30) goto parse_err; - + start = (f1 << 24) | (f2 << 16) | (f3 << 8) | f4; mask = ~((1 << (32 - m)) - 1); start = start & mask; @@ -145,10 +145,10 @@ struct dhcpv4_serv *dhcpv4_create(struct triton_context_t *ctx, const char *ifna addr.sin_addr.s_addr = htonl(INADDR_ANY); sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &f, sizeof(f))) log_error("setsockopt(SO_REUSEADDR): %s\n", strerror(errno)); - + if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &f, sizeof(f))) { log_error("setsockopt(SO_BROADCAST): %s\n", strerror(errno)); @@ -164,15 +164,15 @@ struct dhcpv4_serv *dhcpv4_create(struct triton_context_t *ctx, const char *ifna log_error("setsockopt(SO_BINDTODEVICE): %s\n", strerror(errno)); goto out_err; } - + if (ioctl(sock, SIOCGIFHWADDR, &ifr)) { log_error("dhcpv4(%s): ioctl(SIOCGIFHWADDR): %s\n", ifname, strerror(errno)); goto out_err; } - + fcntl(sock, F_SETFL, O_NONBLOCK); fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC); - + serv = _malloc(sizeof(*serv)); memset(serv, 0, sizeof(*serv)); @@ -186,13 +186,13 @@ struct dhcpv4_serv *dhcpv4_create(struct triton_context_t *ctx, const char *ifna if (opt && *opt) { str0 = _strdup(opt); str = str0; - + while (1) { for (ptr1 = str + 1; *ptr1 && *ptr1 != '='; ptr1++); if (!*ptr1) break; - + *ptr1 = 0; for (ptr2 = ++ptr1; *ptr2 && *ptr2 != ','; ptr2++); @@ -213,7 +213,7 @@ struct dhcpv4_serv *dhcpv4_create(struct triton_context_t *ctx, const char *ifna str = ptr2 + 1; } - + _free(str0); } @@ -301,10 +301,10 @@ static int dhcpv4_parse_packet(struct dhcpv4_packet *pack, int len) log_warn("dhcpv4: short packet received\n"); return -1; } - + if (pack->hdr->htype != 1) return -1; - + if (pack->hdr->hlen != 6) return -1; @@ -318,7 +318,7 @@ static int dhcpv4_parse_packet(struct dhcpv4_packet *pack, int len) ptr++; continue; } - + if (*ptr == 0xff) { ptr++; break; @@ -357,9 +357,9 @@ static int dhcpv4_parse_packet(struct dhcpv4_packet *pack, int len) if (dhcpv4_check_options(pack)) return -1; - + pack->ptr = ptr; - + /*if (conf_verbose) { log_info2("recv "); print_packet(pack, log_info2); @@ -465,7 +465,7 @@ int dhcpv4_packet_insert_opt82(struct dhcpv4_packet *pack, const char *agent_cir r = dhcpv4_packet_add_opt(pack, 82, data, 4 + len1 + len2); _free(data); - + *pack->ptr++ = 255; return r; @@ -500,7 +500,7 @@ static int dhcpv4_read(struct triton_md_handler_t *h) dhcpv4_packet_free(pack); continue; } - + if (pack->hdr->op != DHCP_OP_REQUEST) { dhcpv4_packet_free(pack); continue; @@ -510,7 +510,7 @@ static int dhcpv4_read(struct triton_md_handler_t *h) if (serv->recv) serv->recv(serv, pack); - + dhcpv4_packet_free(pack); } } @@ -542,7 +542,7 @@ static int dhcpv4_relay_read(struct triton_md_handler_t *h) dhcpv4_packet_free(pack); continue; } - + if (pack->hdr->op != DHCP_OP_REPLY) { dhcpv4_packet_free(pack); continue; @@ -564,17 +564,17 @@ uint16_t ip_csum(uint16_t *buf, int len) { uint32_t sum=0; int i; - + for (i=0; i < len; i += 2) sum += *buf++; - + // take only 16 bits out of the 32 bit sum and add up the carries while (sum >> 16) sum = (sum & 0xffff) + (sum >> 16); // one's complement the result sum = ~sum; - + return sum & 0xffff; } @@ -591,7 +591,7 @@ static int dhcpv4_send_raw(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack, struct sockaddr_ll ll_addr; struct msghdr msg; int sock = open_raw_sock(); - + memset(&ll_addr, 0, sizeof(ll_addr)); ll_addr.sll_family = AF_PACKET; ll_addr.sll_ifindex = serv->ifindex; @@ -638,7 +638,7 @@ static int dhcpv4_send_raw(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack, printf("%i %i\n", errno, serv->ifindex); return -1; } - + return 0; } @@ -656,7 +656,7 @@ static int dhcpv4_send_udp(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack, n = sendto(serv->hnd.fd, pack->data, len, 0, (struct sockaddr *)&addr, sizeof(addr)); if (n != len) return -1; - + return 0; } @@ -674,7 +674,7 @@ int dhcpv4_packet_add_opt(struct dhcpv4_packet *pack, int type, const void *data opt->type = type; opt->len = len; - opt->data = pack->ptr; + opt->data = pack->ptr; pack->ptr += len; memcpy(opt->data, data, len); @@ -697,7 +697,7 @@ int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_pack } dns; int dns_avail = 0; struct dhcpv4_option *opt; - + pack = dhcpv4_packet_alloc(); if (!pack) { log_emerg("out of memory\n"); @@ -717,17 +717,17 @@ int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_pack if (dhcpv4_packet_add_opt(pack, 53, &msg_type, 1)) goto out_err; - + if (dhcpv4_packet_add_opt(pack, 54, &siaddr, 4)) goto out_err; - + val = ntohl(lease_time); if (dhcpv4_packet_add_opt(pack, 51, &val, 4)) goto out_err; if (router && dhcpv4_packet_add_opt(pack, 3, &router, 4)) goto out_err; - + val = htonl(~((1 << (32 - mask)) - 1)); if (dhcpv4_packet_add_opt(pack, 1, &val, 4)) goto out_err; @@ -742,7 +742,7 @@ int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_pack goto out_err; } } - + if (!dns_avail) { if (conf_dns1 && conf_dns2) { dns.dns1 = conf_dns1; @@ -783,7 +783,7 @@ int dhcpv4_send_nak(struct dhcpv4_serv *serv, struct dhcpv4_packet *req) { struct dhcpv4_packet *pack; int val, r; - + pack = dhcpv4_packet_alloc(); if (!pack) { log_emerg("out of memory\n"); @@ -801,7 +801,7 @@ int dhcpv4_send_nak(struct dhcpv4_serv *serv, struct dhcpv4_packet *req) val = DHCPNAK; if (dhcpv4_packet_add_opt(pack, 53, &val, 1)) goto out_err; - + *pack->ptr++ = 255; if (conf_verbose) { @@ -837,7 +837,7 @@ struct dhcpv4_relay *dhcpv4_relay_create(const char *_addr, in_addr_t giaddr, st int sock = -1; int f = 1; struct dhcpv4_relay_ctx *c; - + ptr = strchr(_addr, ':'); if (ptr) { memcpy(str, _addr, ptr - _addr); @@ -846,7 +846,7 @@ struct dhcpv4_relay *dhcpv4_relay_create(const char *_addr, in_addr_t giaddr, st port = atoi(ptr + 1); } else addr = inet_addr(_addr); - + memset(&raddr, 0, sizeof(raddr)); raddr.sin_family = AF_INET; raddr.sin_addr.s_addr = addr; @@ -862,7 +862,7 @@ struct dhcpv4_relay *dhcpv4_relay_create(const char *_addr, in_addr_t giaddr, st if (r->addr == addr && r->giaddr == giaddr) goto found; } - + r = _malloc(sizeof(*r)); memset(r, 0, sizeof(*r)); INIT_LIST_HEAD(&r->ctx_list); @@ -877,7 +877,7 @@ struct dhcpv4_relay *dhcpv4_relay_create(const char *_addr, in_addr_t giaddr, st if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &f, sizeof(f))) log_error("dhcpv4: setsockopt(SO_REUSEADDR): %s\n", strerror(errno)); - + if (bind(sock, &laddr, sizeof(laddr))) { log_error("dhcpv4: relay: %s: bind: %s\n", _addr, strerror(errno)); goto out_err_unlock; @@ -887,7 +887,7 @@ struct dhcpv4_relay *dhcpv4_relay_create(const char *_addr, in_addr_t giaddr, st log_error("dhcpv4: relay: %s: connect: %s\n", _addr, strerror(errno)); goto out_err_unlock; } - + fcntl(sock, F_SETFL, O_NONBLOCK); fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC); @@ -908,7 +908,7 @@ found: c->ctx = ctx; c->recv = recv; list_add_tail(&c->entry, &r->ctx_list); - + pthread_mutex_unlock(&relay_lock); return r; @@ -965,11 +965,11 @@ int dhcpv4_relay_send(struct dhcpv4_relay *relay, struct dhcpv4_packet *request, if (server_id) { opt = dhcpv4_packet_find_opt(request, 54); if (opt) { - _server_id = *(uint32_t *)opt->data; + _server_id = *(uint32_t *)opt->data; *(uint32_t *)opt->data = server_id; } } - + if (conf_verbose) { log_ppp_info2("send "); dhcpv4_print_packet(request, 1, log_ppp_info2); @@ -982,10 +982,10 @@ int dhcpv4_relay_send(struct dhcpv4_relay *relay, struct dhcpv4_packet *request, if (opt) *(uint32_t *)opt->data = _server_id; - + if (n != len) return -1; - + return 0; } @@ -1019,7 +1019,7 @@ int dhcpv4_relay_send_release(struct dhcpv4_relay *relay, uint8_t *chaddr, uint3 if (client_id && dhcpv4_packet_add_opt(pack, 61, client_id->data, client_id->len)) goto out_err; - + if (relay_agent && dhcpv4_packet_add_opt(pack, 82, relay_agent->data, relay_agent->len)) goto out_err; else if (!relay_agent) { @@ -1028,18 +1028,18 @@ int dhcpv4_relay_send_release(struct dhcpv4_relay *relay, uint8_t *chaddr, uint3 goto out_err; pack->ptr--; } - + *pack->ptr++ = 255; len = pack->ptr - pack->data; - + if (conf_verbose) { log_ppp_info2("send "); dhcpv4_print_packet(pack, 1, log_ppp_info2); } n = write(relay->hnd.fd, pack->data, len); - + dhcpv4_packet_free(pack); return n == len ? 0 : -1; @@ -1055,7 +1055,7 @@ int dhcpv4_get_ip(struct dhcpv4_serv *serv, uint32_t *yiaddr, uint32_t *siaddr, if (!serv->range) return 0; - + pthread_mutex_lock(&serv->range->lock); while (1) { @@ -1074,7 +1074,7 @@ int dhcpv4_get_ip(struct dhcpv4_serv *serv, uint32_t *yiaddr, uint32_t *siaddr, if (serv->range->pos == 0) break; - + serv->range->pos = 0; } @@ -1097,7 +1097,7 @@ void dhcpv4_put_ip(struct dhcpv4_serv *serv, uint32_t ip) void dhcpv4_reserve_ip(struct dhcpv4_serv *serv, uint32_t ip) { int n = ntohl(ip) - serv->range->startip; - + if (n <= 0 || n / (8 * sizeof(long)) >= serv->range->len) return; @@ -1108,7 +1108,7 @@ void dhcpv4_reserve_ip(struct dhcpv4_serv *serv, uint32_t ip) static void load_config() { - const char *opt; + const char *opt; opt = conf_get_opt("ipoe", "verbose"); if (opt) @@ -1117,7 +1117,7 @@ static void load_config() opt = conf_get_opt("dns", "dns1"); if (opt) conf_dns1 = inet_addr(opt); - + opt = conf_get_opt("dns", "dns2"); if (opt) conf_dns2 = inet_addr(opt); @@ -1127,7 +1127,7 @@ static void init() { pack_pool = mempool_create(BUF_SIZE + sizeof(struct dhcpv4_packet)); opt_pool = mempool_create(sizeof(struct dhcpv4_option)); - + pthread_key_create(&raw_sock_key, close_raw_sock); load_config(); diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.h b/accel-pppd/ctrl/ipoe/dhcpv4.h index 15db8ed5..163c0847 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4.h +++ b/accel-pppd/ctrl/ipoe/dhcpv4.h @@ -80,7 +80,7 @@ struct dhcpv4_iprange { int len; pthread_mutex_t lock; unsigned long free[0]; -}; +}; struct dhcpv4_serv { struct triton_context_t *ctx; diff --git a/accel-pppd/ctrl/ipoe/dhcpv4_options.c b/accel-pppd/ctrl/ipoe/dhcpv4_options.c index f233e7c5..b5f2b3bf 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4_options.c +++ b/accel-pppd/ctrl/ipoe/dhcpv4_options.c @@ -131,7 +131,7 @@ static void print_ip(const struct dhcpv4_option *opt, int elem_size, void (*prin { int i, n = opt->len / elem_size; uint32_t ip; - + for (i = 0; i < n; i++) { ip = ntohl(*(uint32_t *)(opt->data + i*elem_size)); @@ -172,10 +172,10 @@ static void print_route(const struct dhcpv4_option *opt, int elem_size, void (*p for (i = 0; i < n; i++) { ip = ntohl(*(uint32_t *)(opt->data + i*8)); gw = ntohl(*(uint32_t *)(opt->data + i*8 + 4)); - + if (i) print(","); - + print("%i.%i.%i.%i via %i.%i.%i.%i", (ip >> 24) & 0xff, (ip >> 16) & 0xff, @@ -275,7 +275,7 @@ static void print_classless_route(const struct dhcpv4_option *opt, int elem_size ptr += 4; gw = ntohl(*(uint32_t *)ptr); ptr += 4; - + print("%i.%i.%i.%i/%i via %i.%i.%i.%i", (ip >> 24) & 0xff, (ip >> 16) & 0xff, diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index cdb8fb09..cca20964 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -186,7 +186,7 @@ static int ipoe_rad_send_request(struct rad_plugin_t *rad, struct rad_packet_t * static struct ipoe_session *ipoe_session_lookup(struct ipoe_serv *serv, struct dhcpv4_packet *pack, struct ipoe_session **opt82_ses) { struct ipoe_session *ses, *res = NULL; - + uint8_t *agent_circuit_id = NULL; uint8_t *agent_remote_id = NULL; int opt82_match; @@ -201,27 +201,27 @@ static struct ipoe_session *ipoe_session_lookup(struct ipoe_serv *serv, struct d list_for_each_entry(ses, &serv->sessions, entry) { opt82_match = pack->relay_agent != NULL; - + if (agent_circuit_id && !ses->agent_circuit_id) opt82_match = 0; - + if (opt82_match && agent_remote_id && !ses->agent_remote_id) opt82_match = 0; - + if (opt82_match && !agent_circuit_id && ses->agent_circuit_id) opt82_match = 0; - + if (opt82_match && !agent_remote_id && ses->agent_remote_id) opt82_match = 0; - + if (opt82_match && agent_circuit_id) { if (*agent_circuit_id != *ses->agent_circuit_id) opt82_match = 0; - + if (memcmp(agent_circuit_id + 1, ses->agent_circuit_id + 1, *agent_circuit_id)) opt82_match = 0; } - + if (opt82_match && agent_remote_id) { if (*agent_remote_id != *ses->agent_remote_id) opt82_match = 0; @@ -232,19 +232,19 @@ static struct ipoe_session *ipoe_session_lookup(struct ipoe_serv *serv, struct d if (opt82_match && opt82_ses) *opt82_ses = ses; - + if (memcmp(pack->hdr->chaddr, ses->hwaddr, ETH_ALEN)) continue; - + res = ses; break; - + /*if (pack->client_id && !ses->client_id) continue; - + if (!pack->client_id && ses->client_id) continue; - + if (pack->client_id) { if (pack->client_id->len != ses->client_id->len) continue; @@ -262,28 +262,28 @@ static struct ipoe_session *ipoe_session_lookup(struct ipoe_serv *serv, struct d if (!res || !pack->relay_agent || !opt82_ses || *opt82_ses) return res; - + list_for_each_entry(ses, &serv->sessions, entry) { if (agent_circuit_id && !ses->agent_circuit_id) continue; - + if (opt82_match && agent_remote_id && !ses->agent_remote_id) continue; - + if (opt82_match && !agent_circuit_id && ses->agent_circuit_id) continue; - + if (opt82_match && !agent_remote_id && ses->agent_remote_id) continue; - + if (opt82_match && agent_circuit_id) { if (*agent_circuit_id != *ses->agent_circuit_id) continue; - + if (memcmp(agent_circuit_id + 1, ses->agent_circuit_id + 1, *agent_circuit_id)) continue; } - + if (opt82_match && agent_remote_id) { if (*agent_remote_id != *ses->agent_remote_id) continue; @@ -295,7 +295,7 @@ static struct ipoe_session *ipoe_session_lookup(struct ipoe_serv *serv, struct d *opt82_ses = ses; break; } - + return res; } @@ -367,7 +367,7 @@ static void l4_redirect_list_add(in_addr_t addr) memset(n, 0, sizeof(*n)); n->addr = addr; n->timeout = ts.tv_sec + conf_l4_redirect_on_reject; - + ipoe_nl_add_exclude(addr, 32); if (conf_l4_redirect_table) @@ -377,13 +377,13 @@ static void l4_redirect_list_add(in_addr_t addr) ipset_add(conf_l4_redirect_ipset, addr); pthread_rwlock_wrlock(&l4_list_lock); - + list_add_tail(&n->entry, &l4_redirect_list); - + if (!l4_redirect_timer.tpd) triton_timer_add(&l4_redirect_ctx, &l4_redirect_timer, 0); - pthread_rwlock_unlock(&l4_list_lock); + pthread_rwlock_unlock(&l4_list_lock); } static int l4_redirect_list_check(in_addr_t addr) @@ -417,10 +417,10 @@ static void l4_redirect_list_timer(struct triton_timer_t *t) if (conf_l4_redirect_table) iprule_del(n->addr, conf_l4_redirect_table); - + if (conf_l4_redirect_ipset) ipset_del(conf_l4_redirect_ipset, n->addr); - + ipoe_nl_del_exclude(n->addr); _free(n); @@ -438,12 +438,12 @@ static void l4_redirect_list_timer(struct triton_timer_t *t) static void ipoe_change_l4_redirect(struct ipoe_session *ses, int del) { in_addr_t addr; - + if (ses->ses.ipv4) addr = ses->ses.ipv4->peer_addr; else addr = ses->yiaddr; - + if (ses->l4_redirect_table) { if (del) { iprule_del(addr, ses->l4_redirect_table); @@ -560,7 +560,7 @@ cont: if (ses->serv->opt_nat) ses->ses.ipv4 = ipdb_get_ipv4(&ses->ses); - + if (ses->serv->opt_shared == 0 && (!ses->ses.ipv4 || ses->ses.ipv4->peer_addr == ses->yiaddr)) { strncpy(ses->ses.ifname, ses->serv->ifname, AP_IFNAME_LEN); ses->ses.ifindex = ses->serv->ifindex; @@ -586,18 +586,18 @@ static void ipoe_session_start(struct ipoe_session *ses) int r; char *passwd; char *username; - + if (ses->dhcpv4_request && conf_verbose) { log_ppp_info2("recv "); dhcpv4_print_packet(ses->dhcpv4_request, 0, log_ppp_info2); } __sync_add_and_fetch(&stat_starting, 1); - + assert(!ses->ses.username); strncpy(ses->ses.ifname, ses->serv->ifname, AP_IFNAME_LEN); - + username = ipoe_session_get_username(ses); if (!username) { @@ -606,13 +606,13 @@ static void ipoe_session_start(struct ipoe_session *ses) } ses->ses.unit_idx = ses->serv->ifindex; - + triton_event_fire(EV_CTRL_STARTING, &ses->ses); triton_event_fire(EV_CTRL_STARTED, &ses->ses); ap_session_starting(&ses->ses); - - if (conf_noauth) + + if (conf_noauth) r = PWDB_SUCCESS; else { if (ses->serv->opt_shared && ipoe_create_interface(ses)) @@ -628,7 +628,7 @@ static void ipoe_session_start(struct ipoe_session *ses) ses->username = username; r = pwdb_check(&ses->ses, (pwdb_callback)auth_result, ses, username, PPP_PAP, conf_password ? conf_password : username); - + if (r == PWDB_WAIT) return; @@ -642,7 +642,7 @@ static void ipoe_session_start(struct ipoe_session *ses) } } } - + auth_result(ses, r); } @@ -659,7 +659,7 @@ static void find_gw_addr(struct ipoe_session *ses) } } -static void __ipoe_session_start(struct ipoe_session *ses) +static void __ipoe_session_start(struct ipoe_session *ses) { if (!ses->yiaddr) { dhcpv4_get_ip(ses->serv->dhcpv4, &ses->yiaddr, &ses->router, &ses->mask); @@ -676,7 +676,7 @@ static void __ipoe_session_start(struct ipoe_session *ses) if (!ses->yiaddr) ses->yiaddr = ses->ses.ipv4->peer_addr; - + if (!ses->router) ses->router = ses->ses.ipv4->addr; } /*else if (ses->yiaddr) { @@ -686,7 +686,7 @@ static void __ipoe_session_start(struct ipoe_session *ses) ses->ipv4.mask = ses->mask; ses->ipv4.owner = NULL; }*/ - + if (ses->dhcpv4_request) { if (!ses->yiaddr) { log_ppp_error("no free IPv4 address\n"); @@ -696,13 +696,13 @@ static void __ipoe_session_start(struct ipoe_session *ses) if (!ses->router) find_gw_addr(ses); - + if (!ses->mask) ses->mask = conf_netmask; - + if (!ses->mask) ses->mask = 32; - + if (ses->dhcpv4_request->hdr->giaddr) { /*uint32_t mask = ses->mask == 32 ? 0xffffffff : (((1 << ses->mask) - 1) << (32 - ses->mask)); @@ -719,18 +719,18 @@ static void __ipoe_session_start(struct ipoe_session *ses) ses->router = ses->dhcpv4_request->hdr->giaddr; } } - + if (!ses->router) { log_ppp_error("can't determine router address\n"); ap_session_terminate(&ses->ses, TERM_NAS_REQUEST, 0); return; - } - + } + if (!ses->siaddr && ses->router != ses->yiaddr) ses->siaddr = ses->router; - + if (!ses->siaddr) - ses->siaddr = ses->serv->opt_src; + ses->siaddr = ses->serv->opt_src; if (!ses->siaddr && ses->serv->dhcpv4_relay) ses->siaddr = ses->serv->dhcpv4_relay->giaddr; @@ -748,7 +748,7 @@ static void __ipoe_session_start(struct ipoe_session *ses) dhcpv4_packet_free(ses->dhcpv4_request); ses->dhcpv4_request = NULL; - + ses->timer.expire = ipoe_session_timeout; ses->timer.period = 0; ses->timer.expire_tv.tv_sec = conf_offer_timeout; @@ -756,7 +756,7 @@ static void __ipoe_session_start(struct ipoe_session *ses) } else { if (!ses->siaddr) find_gw_addr(ses); - + if (!ses->siaddr) ses->siaddr = ses->serv->opt_src; @@ -768,7 +768,7 @@ static void __ipoe_session_start(struct ipoe_session *ses) ap_session_terminate(&ses->ses, TERM_NAS_ERROR, 0); return; } - + if (ses->ses.ipv4 && !ses->ses.ipv4->addr) ses->ses.ipv4->addr = ses->siaddr; @@ -781,7 +781,7 @@ static void ipoe_serv_add_addr(struct ipoe_serv *serv, in_addr_t addr, int mask) struct ifaddr *a; pthread_mutex_lock(&serv->lock); - + if (serv->opt_shared) { list_for_each_entry(a, &serv->addr_list, entry) { if (a->addr == addr) { @@ -823,7 +823,7 @@ static void ipoe_serv_del_addr(struct ipoe_serv *serv, in_addr_t addr, int lock) break; } } - + if (lock) pthread_mutex_unlock(&serv->lock); } @@ -834,7 +834,7 @@ static void ipoe_ifcfg_add(struct ipoe_session *ses) if (ses->serv->opt_ifcfg) ipoe_serv_add_addr(ses->serv, ses->siaddr, conf_ip_unnumbered ? 32 : ses->mask); - + if (conf_ip_unnumbered) { if (iproute_add(serv->ifindex, ses->serv->opt_src ? ses->serv->opt_src : ses->router, ses->yiaddr, 0, conf_proto)) log_ppp_warn("ipoe: failed to add route to interface '%s'\n", serv->ifname); @@ -846,7 +846,7 @@ static void ipoe_ifcfg_add(struct ipoe_session *ses) static void ipoe_ifcfg_del(struct ipoe_session *ses, int lock) { struct ipoe_serv *serv = ses->serv; - + if (conf_ip_unnumbered) { if (iproute_del(serv->ifindex, ses->yiaddr, conf_proto)) log_ppp_warn("ipoe: failed to delete route from interface '%s'\n", serv->ifname); @@ -862,7 +862,7 @@ static void __ipoe_session_activate(struct ipoe_session *ses) if (ses->terminating) return; - + if (ses->ifindex != -1) { addr = 0; if (!ses->ses.ipv4) { @@ -889,29 +889,29 @@ static void __ipoe_session_activate(struct ipoe_session *ses) return; } } - + if (!ses->ses.ipv4) { ses->ses.ipv4 = &ses->ipv4; ses->ipv4.owner = NULL; ses->ipv4.peer_addr = ses->yiaddr; ses->ipv4.addr = ses->siaddr; } - + if (ses->ifindex == -1) { if (ses->serv->opt_ifcfg || (ses->serv->opt_mode == MODE_L2)) ipoe_ifcfg_add(ses); - + ipoe_nl_add_exclude(ses->yiaddr, 32); iproute_add(ses->serv->ifindex, ses->siaddr, ses->yiaddr, 0, conf_proto); - + ses->ctrl.dont_ifcfg = 1; } else if (ses->ctrl.dont_ifcfg && ses->serv->opt_mode == MODE_L2) ipaddr_add(ses->ifindex, ses->siaddr, ses->mask); - + if (ses->l4_redirect) ipoe_change_l4_redirect(ses, 0); - + if (ses->serv->opt_mode == MODE_L2 && ses->serv->opt_ipv6 && sock6_fd != -1) { ses->ses.ipv6 = ipdb_get_ipv6(&ses->ses); if (!ses->ses.ipv6) @@ -935,7 +935,7 @@ static void __ipoe_session_activate(struct ipoe_session *ses) dhcpv4_packet_free(ses->dhcpv4_request); ses->dhcpv4_request = NULL; } - + ses->timer.expire = ipoe_session_timeout; ses->timer.period = 0; ses->timer.expire_tv.tv_sec = conf_lease_timeout ? conf_lease_timeout : ses->lease_time; @@ -946,7 +946,7 @@ static void __ipoe_session_activate(struct ipoe_session *ses) static void ipoe_session_activate(struct dhcpv4_packet *pack) { struct ipoe_session *ses = container_of(triton_context_self(), typeof(*ses), ctx); - + if (ses->ses.state == AP_STATE_ACTIVE) { ipoe_session_keepalive(pack); return; @@ -954,7 +954,7 @@ static void ipoe_session_activate(struct dhcpv4_packet *pack) if (ses->dhcpv4_request) dhcpv4_packet_free(ses->dhcpv4_request); - + ses->dhcpv4_request = pack; if (ses->serv->dhcpv4_relay) @@ -969,14 +969,14 @@ static void ipoe_session_keepalive(struct dhcpv4_packet *pack) if (ses->dhcpv4_request) dhcpv4_packet_free(ses->dhcpv4_request); - + ses->dhcpv4_request = pack; if (ses->timer.tpd) triton_timer_mod(&ses->timer, 0); ses->xid = ses->dhcpv4_request->hdr->xid; - + if (/*ses->ses.state == AP_STATE_ACTIVE &&*/ ses->serv->dhcpv4_relay) { dhcpv4_relay_send(ses->serv->dhcpv4_relay, ses->dhcpv4_request, ses->relay_server_id, ses->serv->ifname, conf_agent_remote_id); return; @@ -990,7 +990,7 @@ static void ipoe_session_keepalive(struct dhcpv4_packet *pack) dhcpv4_packet_free(ses->dhcpv4_request); ses->dhcpv4_request = NULL; } - + static void ipoe_session_decline(struct dhcpv4_packet *pack) { struct ipoe_session *ses = container_of(triton_context_self(), typeof(*ses), ctx); @@ -999,7 +999,7 @@ static void ipoe_session_decline(struct dhcpv4_packet *pack) log_ppp_info2("recv "); dhcpv4_print_packet(pack, 0, log_ppp_info2); } - + if (pack->msg_type == DHCPDECLINE && ses->serv->dhcpv4_relay) dhcpv4_relay_send(ses->serv->dhcpv4_relay, pack, 0, ses->serv->ifname, conf_agent_remote_id); @@ -1011,12 +1011,12 @@ static void ipoe_session_decline(struct dhcpv4_packet *pack) static void ipoe_session_started(struct ap_session *s) { struct ipoe_session *ses = container_of(s, typeof(*ses), ses); - + log_ppp_info1("ipoe: session started\n"); if (ses->timer.tpd) triton_timer_mod(&ses->timer, 0); - + if (ses->ifindex != -1 && ses->xid) { ses->dhcpv4 = dhcpv4_create(ses->ctrl.ctx, ses->ses.ifname, ""); if (!ses->dhcpv4) { @@ -1033,33 +1033,33 @@ static void ipoe_session_free(struct ipoe_session *ses) __sync_sub_and_fetch(&stat_active, 1); else __sync_sub_and_fetch(&stat_starting, 1); - + if (ses->timer.tpd) triton_timer_del(&ses->timer); - + if (ses->l4_redirect_timer.tpd) triton_timer_del(&ses->timer); if (ses->dhcpv4_request) dhcpv4_packet_free(ses->dhcpv4_request); - + if (ses->dhcpv4_relay_reply) dhcpv4_packet_free(ses->dhcpv4_relay_reply); - + if (ses->ctrl.called_station_id) _free(ses->ctrl.called_station_id); - + if (ses->ctrl.calling_station_id) _free(ses->ctrl.calling_station_id); - + if (ses->l4_redirect_ipset) _free(ses->l4_redirect_ipset); triton_context_unregister(&ses->ctx); - + if (ses->data) _free(ses->data); - + mempool_free(ses); } @@ -1097,12 +1097,12 @@ static void ipoe_session_finished(struct ap_session *s) if (ses->ifcfg) ipoe_ifcfg_del(ses, 1); - + if (ses->dhcpv4) dhcpv4_free(ses->dhcpv4); triton_event_fire(EV_CTRL_FINISHED, s); - + triton_context_call(&ses->ctx, (triton_event_func)ipoe_session_free, ses); } @@ -1120,7 +1120,7 @@ static void ipoe_session_terminate(struct ap_session *s, int hard) static void ipoe_session_close(struct triton_context_t *ctx) { struct ipoe_session *ses = container_of(ctx, typeof(*ses), ctx); - + if (ses->ses.state) ap_session_terminate(&ses->ses, TERM_ADMIN_RESET, 1); else @@ -1132,7 +1132,7 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s struct ipoe_session *ses; int dlen = 0; uint8_t *ptr = NULL; - + ses = ipoe_session_alloc(); if (!ses) return NULL; @@ -1140,7 +1140,7 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s ses->serv = serv; ses->dhcpv4_request = pack; strncpy(ses->ses.ifname, serv->ifname, AP_IFNAME_LEN); - + ses->xid = pack->hdr->xid; memcpy(ses->hwaddr, pack->hdr->chaddr, 6); ses->giaddr = pack->hdr->giaddr; @@ -1148,10 +1148,10 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s if (pack->client_id) dlen += sizeof(struct dhcpv4_option) + pack->client_id->len; - + if (pack->relay_agent) dlen += sizeof(struct dhcpv4_option) + pack->relay_agent->len; - + if (dlen) { ses->data = _malloc(dlen); if (!ses->data) { @@ -1169,7 +1169,7 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s memcpy(ses->client_id->data, pack->client_id->data, pack->client_id->len); ptr += sizeof(struct dhcpv4_option) + pack->client_id->len; } - + if (pack->relay_agent) { ses->relay_agent = (struct dhcpv4_option *)ptr; ses->relay_agent->len = pack->relay_agent->len; @@ -1181,14 +1181,14 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s } ses->ctrl.dont_ifcfg = 1; - + ses->ctrl.calling_station_id = _malloc(19); ses->ctrl.called_station_id = _strdup(serv->ifname); - + ptr = ses->hwaddr; sprintf(ses->ctrl.calling_station_id, "%02x:%02x:%02x:%02x:%02x:%02x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); - + ses->ses.ctrl = &ses->ctrl; ses->ses.chan_name = ses->ctrl.calling_station_id; @@ -1202,10 +1202,10 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s //pthread_mutex_lock(&serv->lock); list_add_tail(&ses->entry, &serv->sessions); //pthread_mutex_unlock(&serv->lock); - + if (serv->timer.tpd) triton_timer_del(&serv->timer); - + dhcpv4_packet_ref(pack); triton_context_call(&ses->ctx, (triton_event_func)ipoe_session_start, ses); @@ -1227,7 +1227,7 @@ static void ipoe_ses_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packe if (ap_shutdown) return; - + if (conf_verbose) { log_ppp_info2("recv "); dhcpv4_print_packet(pack, 0, log_ppp_info2); @@ -1239,27 +1239,27 @@ static void ipoe_ses_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packe } opt82_match = pack->relay_agent != NULL; - + if (agent_circuit_id && !ses->agent_circuit_id) opt82_match = 0; - + if (opt82_match && agent_remote_id && !ses->agent_remote_id) opt82_match = 0; - + if (opt82_match && !agent_circuit_id && ses->agent_circuit_id) opt82_match = 0; - + if (opt82_match && !agent_remote_id && ses->agent_remote_id) opt82_match = 0; - + if (opt82_match && agent_circuit_id) { if (*agent_circuit_id != *ses->agent_circuit_id) opt82_match = 0; - + if (memcmp(agent_circuit_id + 1, ses->agent_circuit_id + 1, *agent_circuit_id)) opt82_match = 0; } - + if (opt82_match && agent_remote_id) { if (*agent_remote_id != *ses->agent_remote_id) opt82_match = 0; @@ -1295,7 +1295,7 @@ static void ipoe_ses_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packe dhcpv4_send_nak(dhcpv4, pack); else if (ses->serv->dhcpv4_relay) dhcpv4_relay_send(ses->serv->dhcpv4_relay, pack, 0, ses->serv->ifname, conf_agent_remote_id); - + triton_context_call(ses->ctrl.ctx, (triton_event_func)__ipoe_session_terminate, &ses->ses); } else { dhcpv4_packet_ref(pack); @@ -1315,10 +1315,10 @@ static void ipoe_ses_recv_dhcpv4_discover(struct dhcpv4_packet *pack) log_ppp_info2("recv "); dhcpv4_print_packet(pack, 0, log_ppp_info2); } - + if (ses->yiaddr) dhcpv4_send_reply(DHCPOFFER, ses->serv->dhcpv4, pack, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply); - + dhcpv4_packet_free(pack); } @@ -1327,12 +1327,12 @@ static void ipoe_ses_recv_dhcpv4_request(struct dhcpv4_packet *pack) struct ipoe_session *ses = container_of(triton_context_self(), typeof(*ses), ctx); ses->xid = pack->hdr->xid; - + if (conf_verbose) { log_ppp_info2("recv "); dhcpv4_print_packet(pack, 0, log_ppp_info2); } - + if ((pack->server_id && (pack->server_id != ses->siaddr || pack->request_ip != ses->yiaddr)) || (pack->hdr->ciaddr && (pack->hdr->ciaddr != ses->yiaddr))) { @@ -1361,10 +1361,10 @@ static void ipoe_serv_disc_timer(struct triton_timer_t *t) int delay, offer_delay; clock_gettime(CLOCK_MONOTONIC, &ts); - - while (!list_empty(&serv->disc_list)) { + + while (!list_empty(&serv->disc_list)) { d = list_entry(serv->disc_list.next, typeof(*d), entry); - + delay = (ts.tv_sec - d->ts.tv_sec) * 1000 + (ts.tv_nsec - d->ts.tv_nsec) / 1000000; offer_delay = get_offer_delay(); @@ -1375,7 +1375,7 @@ static void ipoe_serv_disc_timer(struct triton_timer_t *t) triton_timer_mod(t, 0); return; } - + __ipoe_recv_dhcpv4(serv->dhcpv4, d->pack, 1); list_del(&d->entry); @@ -1394,14 +1394,14 @@ static void ipoe_serv_add_disc(struct ipoe_serv *serv, struct dhcpv4_packet *pac if (!d) return; - + __sync_add_and_fetch(&stat_delayed_offer, 1); - + dhcpv4_packet_ref(pack); d->pack = pack; clock_gettime(CLOCK_MONOTONIC, &d->ts); list_add_tail(&d->entry, &serv->disc_list); - + if (!serv->disc_timer.tpd) { serv->disc_timer.expire_tv.tv_sec = offer_delay / 1000; serv->disc_timer.expire_tv.tv_usec = (offer_delay % 1000) * 1000; @@ -1419,13 +1419,13 @@ static void ipoe_serv_check_disc(struct ipoe_serv *serv, struct dhcpv4_packet *p if (memcmp(d->pack->hdr->chaddr, pack->hdr->chaddr, ETH_ALEN)) continue; - + list_del(&d->entry); dhcpv4_packet_free(d->pack); mempool_free(d); - + __sync_sub_and_fetch(&stat_delayed_offer, 1); - + break; } } @@ -1456,7 +1456,7 @@ static int ipoe_serv_request_check(struct ipoe_serv *serv, uint32_t xid) mempool_free(r); } } - + r = mempool_alloc(req_item_pool); r->xid = xid; r->expire = ts.tv_sec + 30; @@ -1481,7 +1481,7 @@ static void port_change_detected(struct dhcpv4_packet *pack) ap_session_terminate(&ses->ses, TERM_USER_REQUEST, 0); } - + static void mac_change_detected(struct dhcpv4_packet *pack) { struct ipoe_session *ses = container_of(triton_context_self(), typeof(*ses), ctx); @@ -1490,11 +1490,11 @@ static void mac_change_detected(struct dhcpv4_packet *pack) log_ppp_info2("recv "); dhcpv4_print_packet(pack, 0, log_ppp_info2); } - + dhcpv4_packet_free(pack); - + log_ppp_warn("mac change detected\n"); - + ap_session_terminate(&ses->ses, TERM_USER_REQUEST, 0); } @@ -1510,7 +1510,7 @@ static void __ipoe_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packet if (ap_shutdown) return; - + if (connlimit_loaded && pack->msg_type == DHCPDISCOVER && connlimit_check(serv->opt_shared ? cl_key_from_mac(pack->hdr->chaddr) : serv->ifindex)) return; @@ -1543,13 +1543,13 @@ static void __ipoe_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packet triton_context_call(&opt82_ses->ctx, (triton_event_func)__ipoe_session_terminate, &opt82_ses->ses); goto out; } - + dhcpv4_packet_ref(pack); triton_context_call(&ses->ctx, (triton_event_func)ipoe_ses_recv_dhcpv4_discover, pack); } } else if (pack->msg_type == DHCPREQUEST) { ipoe_serv_check_disc(serv, pack); - + ses = ipoe_session_lookup(serv, pack, &opt82_ses); if (!ses) { @@ -1576,7 +1576,7 @@ static void __ipoe_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packet triton_context_call(&opt82_ses->ctx, (triton_event_func)__ipoe_session_terminate, &opt82_ses->ses); goto out; } - + if (serv->opt_shared == 0) ipoe_drop_sessions(serv, ses); @@ -1617,7 +1617,7 @@ static void ipoe_ses_recv_dhcpv4_relay(struct dhcpv4_packet *pack) if (ses->dhcpv4_relay_reply) dhcpv4_packet_free(ses->dhcpv4_relay_reply); - + if (!ses->dhcpv4_request) { ses->dhcpv4_relay_reply = NULL; return; @@ -1667,7 +1667,7 @@ static void ipoe_ses_recv_dhcpv4_relay(struct dhcpv4_packet *pack) ap_session_terminate(&ses->ses, TERM_NAS_REQUEST, 0); return; } - + dhcpv4_packet_free(ses->dhcpv4_relay_reply); ses->dhcpv4_relay_reply = NULL; } @@ -1694,7 +1694,7 @@ static void ipoe_recv_dhcpv4_relay(struct dhcpv4_packet *pack) found = 1; break; } - + if (found) { triton_context_call(&ses->ctx, (triton_event_func)ipoe_ses_recv_dhcpv4_relay, pack); } else @@ -1710,10 +1710,10 @@ static struct ipoe_session *ipoe_session_create_up(struct ipoe_serv *serv, struc if (ap_shutdown) return NULL; - + if (l4_redirect_list_check(iph->saddr)) return NULL; - + ses = ipoe_session_alloc(); if (!ses) return NULL; @@ -1726,12 +1726,12 @@ static struct ipoe_session *ipoe_session_create_up(struct ipoe_serv *serv, struc ses->ctrl.called_station_id = _strdup(serv->ifname); u_inet_ntoa(iph->saddr, ses->ctrl.calling_station_id); - + ses->ses.chan_name = ses->ctrl.calling_station_id; - + if (conf_ip_pool) ses->ses.ipv4_pool_name = _strdup(conf_ip_pool); - + triton_context_register(&ses->ctx, &ses->ses); triton_context_wakeup(&ses->ctx); @@ -1763,7 +1763,7 @@ struct ipoe_session *ipoe_session_alloc(void) ap_session_init(&ses->ses); ses->ifindex = -1; - + ses->ctx.before_switch = log_switch; ses->ctx.close = ipoe_session_close; ses->ctrl.ctx = &ses->ctx; @@ -1775,7 +1775,7 @@ struct ipoe_session *ipoe_session_alloc(void) ses->l4_redirect_table = conf_l4_redirect_table; ses->ses.ctrl = &ses->ctrl; - + return ses; } @@ -1790,7 +1790,7 @@ void ipoe_recv_up(int ifindex, struct ethhdr *eth, struct iphdr *iph) if (!serv->opt_up) return; - + pthread_mutex_lock(&serv->lock); list_for_each_entry(ses, &serv->sessions, entry) { if (ses->yiaddr == iph->saddr) { @@ -1799,7 +1799,7 @@ void ipoe_recv_up(int ifindex, struct ethhdr *eth, struct iphdr *iph) } } pthread_mutex_unlock(&serv->lock); - + ipoe_session_create_up(serv, eth, iph); break; @@ -1853,10 +1853,10 @@ static void ev_radius_coa(struct ev_radius_t *ev) struct ipoe_session *ses = container_of(ev->ses, typeof(*ses), ses); struct rad_attr_t *attr; int l4_redirect; - + if (ev->ses->ctrl->type != CTRL_TYPE_IPOE) return; - + l4_redirect = ses->l4_redirect; list_for_each_entry(attr, &ev->request->attrs, entry) { @@ -1883,8 +1883,8 @@ static int ipoe_rad_send_request(struct rad_plugin_t *rad, struct rad_packet_t * if (!ses->relay_agent) return 0; - - return rad_packet_add_octets(pack, NULL, conf_attr_dhcp_opt82, ses->relay_agent->data, ses->relay_agent->len); + + return rad_packet_add_octets(pack, NULL, conf_attr_dhcp_opt82, ses->relay_agent->data, ses->relay_agent->len); } #endif @@ -1906,7 +1906,7 @@ static void ipoe_serv_release(struct ipoe_serv *serv) return; } - + log_info2("ipoe: stop interface %s\n", serv->ifname); pthread_mutex_lock(&serv_lock); @@ -1915,7 +1915,7 @@ static void ipoe_serv_release(struct ipoe_serv *serv) if (serv->dhcpv4) dhcpv4_free(serv->dhcpv4); - + if (serv->dhcpv4_relay) { ipoe_serv_del_addr(serv, serv->dhcpv4_relay->giaddr, 0); dhcpv4_relay_free(serv->dhcpv4_relay, &serv->ctx); @@ -1931,7 +1931,7 @@ static void ipoe_serv_release(struct ipoe_serv *serv) mempool_free(d); __sync_sub_and_fetch(&stat_delayed_offer, 1); } - + while (!list_empty(&serv->req_list)) { struct request_item *r = list_first_entry(&serv->req_list, typeof(*r), entry); list_del(&r->entry); @@ -1940,7 +1940,7 @@ static void ipoe_serv_release(struct ipoe_serv *serv) if (serv->disc_timer.tpd) triton_timer_del(&serv->disc_timer); - + if (serv->timer.tpd) triton_timer_del(&serv->timer); @@ -1982,19 +1982,19 @@ static void l4_redirect_ctx_close(struct triton_context_t *ctx) if (conf_l4_redirect_table) iprule_del(n->addr, conf_l4_redirect_table); - + if (conf_l4_redirect_ipset) ipset_del(conf_l4_redirect_ipset, n->addr); - + ipoe_nl_del_exclude(n->addr); - + _free(n); } pthread_rwlock_unlock(&l4_list_lock); if (l4_redirect_timer.tpd) triton_timer_del(&l4_redirect_timer); - + triton_context_unregister(&l4_redirect_ctx); } @@ -2066,7 +2066,7 @@ static int get_offer_delay() if (prev) return prev->delay; - + return 0; } @@ -2118,12 +2118,12 @@ void ipoe_vlan_notify(int ifindex, int vid) log_error("ipoe: vlan-mon: failed to get interface name, ifindex=%i\n", ifindex); return; } - + if (make_vlan_name(ifr.ifr_name, vid, ifname)) { log_error("ipoe: vlan-mon: %s.%i: interface name is too long\n", ifr.ifr_name, vid); return; } - + log_info2("ipoe: create vlan %s parent %s\n", ifname, ifr.ifr_name); strcpy(ifr.ifr_name, ifname); @@ -2133,11 +2133,11 @@ void ipoe_vlan_notify(int ifindex, int vid) log_warn("ipoe: vlan-mon: %s: failed to add vlan\n", ifr.ifr_name); return; } - + ioctl(sock_fd, SIOCGIFFLAGS, &ifr, sizeof(ifr)); ifr.ifr_flags |= IFF_UP; ioctl(sock_fd, SIOCSIFFLAGS, &ifr, sizeof(ifr)); - + if (ioctl(sock_fd, SIOCGIFINDEX, &ifr, sizeof(ifr))) { log_error("ipoe: vlan-mon: %s: failed to get interface index\n", ifr.ifr_name); return; @@ -2148,7 +2148,7 @@ void ipoe_vlan_notify(int ifindex, int vid) continue; if (!opt->val) continue; - + ptr = strchr(opt->val, ','); if (!ptr) ptr = strchr(opt->val, 0); @@ -2157,20 +2157,20 @@ void ipoe_vlan_notify(int ifindex, int vid) pattern = _malloc(ptr - (opt->val + 3) + 1); memcpy(pattern, opt->val + 3, ptr - (opt->val + 3)); pattern[ptr - (opt->val + 3)] = 0; - + re = pcre_compile2(pattern, 0, NULL, &pcre_err, &pcre_offset, NULL); - + _free(pattern); - + if (!re) continue; r = pcre_exec(re, NULL, ifr.ifr_name, len, 0, 0, NULL, 0); pcre_free(re); - + if (r < 0) continue; - + add_interface(ifr.ifr_name, ifr.ifr_ifindex, opt->val, ifindex, vid); } else if (ptr - opt->val == len && memcmp(opt->val, ifr.ifr_name, len) == 0) add_interface(ifr.ifr_name, ifr.ifr_ifindex, opt->val, ifindex, vid); @@ -2182,7 +2182,7 @@ static void ipoe_serv_timeout(struct triton_timer_t *t) struct ipoe_serv *serv = container_of(t, typeof(*serv), timer); serv->need_close = 1; - + ipoe_serv_release(serv); } @@ -2213,13 +2213,13 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int if (str0) { str0 = _strdup(str0 + 1); str = str0; - + while (1) { for (ptr1 = str + 1; *ptr1 && *ptr1 != '='; ptr1++); if (!*ptr1) goto parse_err; - + *ptr1 = 0; for (ptr2 = ++ptr1; *ptr2 && *ptr2 != ','; ptr2++); @@ -2270,7 +2270,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int else if (strlen(ptr1) > 4 && memcmp(ptr1, "lua:", 4) == 0) { opt_username = USERNAME_LUA; opt_lua_username_func = _strdup(ptr1 + 4); - } + } #endif else log_error("ipoe: unknown username value '%s'\n", ptr1); @@ -2297,14 +2297,14 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int addr.sin_family = AF_INET; addr.sin_addr.s_addr = relay_addr; addr.sin_port = htons(DHCP_SERV_PORT); - + sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); - + if (connect(sock, &addr, sizeof(addr))) { log_error("dhcpv4: relay: %s: connect: %s\n", opt_relay, strerror(errno)); goto out_err; } - + getsockname(sock, &addr, &len); opt_giaddr = addr.sin_addr.s_addr; @@ -2321,7 +2321,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int serv->active = 1; serv->ifindex = ifindex; - + if ((opt_shared && !serv->opt_shared) || (!opt_shared && serv->opt_shared)) { ipoe_drop_sessions(serv, NULL); serv->opt_shared = opt_shared; @@ -2336,7 +2336,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int serv->dhcpv4 = NULL; } - if (serv->dhcpv4_relay && + if (serv->dhcpv4_relay && (serv->dhcpv4_relay->addr != relay_addr || serv->dhcpv4_relay->giaddr != opt_giaddr)) { if (serv->opt_ifcfg) ipoe_serv_del_addr(serv, serv->dhcpv4_relay->giaddr, 0); @@ -2355,7 +2355,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int serv->arp = NULL; } else if (!serv->arp && conf_arp) serv->arp = arpd_start(serv); - + serv->opt_up = opt_up; serv->opt_mode = opt_mode; serv->opt_ifcfg = opt_ifcfg; @@ -2369,7 +2369,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int _free(serv->opt_lua_username_func); serv->opt_lua_username_func = NULL; } - + if (!serv->opt_lua_username_func && opt_lua_username_func) serv->opt_lua_username_func = opt_lua_username_func; else if (opt_lua_username_func) @@ -2392,14 +2392,14 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, ifname); - + if (ioctl(sock_fd, SIOCGIFHWADDR, &ifr)) { log_error("ipoe: '%s': ioctl(SIOCGIFHWADDR): %s\n", ifname, strerror(errno)); return; } - + ioctl(sock_fd, SIOCGIFFLAGS, &ifr); - + if (!(ifr.ifr_flags & IFF_UP)) { ifr.ifr_flags |= IFF_UP; @@ -2435,14 +2435,14 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int INIT_LIST_HEAD(&serv->req_list); memcpy(serv->hwaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); serv->disc_timer.expire = ipoe_serv_disc_timer; - + triton_context_register(&serv->ctx, NULL); if (serv->opt_dhcpv4) { serv->dhcpv4 = dhcpv4_create(&serv->ctx, serv->ifname, opt); if (serv->dhcpv4) serv->dhcpv4->recv = ipoe_recv_dhcpv4; - + if (opt_relay) { if (opt_ifcfg) ipoe_serv_add_addr(serv, opt_giaddr, 32); @@ -2452,7 +2452,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int if (serv->opt_arp) serv->arp = arpd_start(serv); - + if (vid) { serv->timer.expire = ipoe_serv_timeout; serv->timer.expire_tv.tv_sec = conf_vlan_timeout; @@ -2488,12 +2488,12 @@ static void load_interface(const char *opt) memcpy(ifr.ifr_name, opt, ptr - opt); ifr.ifr_name[ptr - opt] = 0; - + if (ioctl(sock_fd, SIOCGIFINDEX, &ifr)) { log_error("ipoe: '%s': ioctl(SIOCGIFINDEX): %s\n", ifr.ifr_name, strerror(errno)); return; } - + add_interface(ifr.ifr_name, ifr.ifr_ifindex, opt, 0, 0); } @@ -2517,13 +2517,13 @@ static void load_interface_re(const char *opt) struct iplink_arg arg; for (ptr = opt; *ptr && *ptr != ','; ptr++); - + pattern = _malloc(ptr - (opt + 3) + 1); memcpy(pattern, opt + 3, ptr - (opt + 3)); pattern[ptr - (opt + 3)] = 0; - + re = pcre_compile2(pattern, 0, NULL, &pcre_err, &pcre_offset, NULL); - + if (!re) { log_error("ipoe: '%s': %s at %i\r\n", pattern, pcre_err, pcre_offset); return; @@ -2559,7 +2559,7 @@ static void load_interfaces(struct conf_sect_t *sect) else load_interface(opt->val); } - + list_for_each_entry(serv, &serv_list, entry) { if (!serv->active && !serv->vid) { ipoe_drop_sessions(serv, NULL); @@ -2664,7 +2664,7 @@ static void parse_conf_rad_attr(const char *opt, int *val) struct rad_dict_attr_t *attr; opt = conf_get_opt("ipoe", opt); - + *val = 0; if (opt) { @@ -2798,11 +2798,11 @@ static int parse_vlan_mon(const char *opt, long *mask) log_error("ipoe: vlan-mon=%s: invalid vlan %i\n", opt, vid2); return -1; } - + for (; vid < vid2; vid++) mask[vid / (8*sizeof(long))] &= ~(1lu << (vid % (8*sizeof(long)))); } - + mask[vid / (8*sizeof(long))] &= ~(1lu << (vid % (8*sizeof(long)))); if (*ptr2 == 0) @@ -2815,7 +2815,7 @@ static int parse_vlan_mon(const char *opt, long *mask) } return 0; - + out_err: log_error("ipoe: vlan-mon=%s: failed to parse\n", opt); return -1; @@ -2828,16 +2828,16 @@ static void add_vlan_mon(const char *opt, long *mask) int ifindex; long mask1[4096/8/sizeof(long)]; struct ipoe_serv *serv; - + for (ptr = opt; *ptr && *ptr != ','; ptr++); - + if (ptr - opt >= sizeof(ifr.ifr_name)) { log_error("ipoe: vlan-mon=%s: interface name is too long\n", opt); return; } memset(&ifr, 0, sizeof(ifr)); - + memcpy(ifr.ifr_name, opt, ptr - opt); ifr.ifr_name[ptr - opt] = 0; @@ -2847,9 +2847,9 @@ static void add_vlan_mon(const char *opt, long *mask) } ifindex = ifr.ifr_ifindex; - + ioctl(sock_fd, SIOCGIFFLAGS, &ifr); - + if (!(ifr.ifr_flags & IFF_UP)) { ifr.ifr_flags |= IFF_UP; @@ -2876,15 +2876,15 @@ static int __load_vlan_mon_re(int index, int flags, const char *name, struct ipl memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, name); - + ioctl(sock_fd, SIOCGIFFLAGS, &ifr); - + if (!(ifr.ifr_flags & IFF_UP)) { ifr.ifr_flags |= IFF_UP; ioctl(sock_fd, SIOCSIFFLAGS, &ifr); } - + memcpy(mask1, arg->arg1, sizeof(mask1)); list_for_each_entry(serv, &serv_list, entry) { if (serv->vid && serv->parent_ifindex == index) @@ -2906,13 +2906,13 @@ static void load_vlan_mon_re(const char *opt, long *mask, int len) struct iplink_arg arg; for (ptr = opt; *ptr && *ptr != ','; ptr++); - + pattern = _malloc(ptr - (opt + 3) + 1); memcpy(pattern, opt + 3, ptr - (opt + 3)); pattern[ptr - (opt + 3)] = 0; - + re = pcre_compile2(pattern, 0, NULL, &pcre_err, &pcre_offset, NULL); - + if (!re) { log_error("ipoe: '%s': %s at %i\r\n", pattern, pcre_err, pcre_offset); return; @@ -2942,7 +2942,7 @@ static void load_vlan_mon(struct conf_sect_t *sect) if (!opt->val) continue; - + if (parse_vlan_mon(opt->val, mask)) continue; @@ -2977,7 +2977,7 @@ static void load_config(void) log_emerg("ipoe: unknown username value '%s'\n", opt); } else conf_username = USERNAME_UNSET; - + opt = conf_get_opt("ipoe", "password"); if (opt) { if (!strcmp(opt, "username")) @@ -2998,7 +2998,7 @@ static void load_config(void) } } else conf_netmask = 0; - + opt = conf_get_opt("ipoe", "verbose"); if (opt) conf_verbose = atoi(opt); @@ -3008,49 +3008,49 @@ static void load_config(void) conf_lease_time = atoi(opt); else conf_lease_time = 600; - + opt = conf_get_opt("ipoe", "max-lease-time"); if (opt) conf_lease_timeout = atoi(opt); else conf_lease_timeout = 660; - + opt = conf_get_opt("ipoe", "unit-cache"); if (opt) conf_unit_cache = atoi(opt); - + opt = conf_get_opt("ipoe", "l4-redirect-table"); if (opt && atoi(opt) > 0) conf_l4_redirect_table = atoi(opt); else conf_l4_redirect_table = 0; - + conf_l4_redirect_ipset = conf_get_opt("ipoe", "l4-redirect-ipset"); - + opt = conf_get_opt("ipoe", "l4-redirect-on-reject"); if (opt) { conf_l4_redirect_on_reject = atoi(opt); } else conf_l4_redirect_on_reject = 0; - + if (conf_l4_redirect_on_reject) { l4_redirect_timer.period = conf_l4_redirect_on_reject / 10 * 1000; if (l4_redirect_timer.tpd) triton_timer_mod(&l4_redirect_timer, 0); } - + opt = conf_get_opt("ipoe", "shared"); if (opt) conf_shared = atoi(opt); else conf_shared = 1; - + opt = conf_get_opt("ipoe", "ifcfg"); if (opt) conf_ifcfg = atoi(opt); else conf_ifcfg = 1; - + opt = conf_get_opt("ipoe", "nat"); if (opt) conf_nat = atoi(opt); @@ -3068,12 +3068,12 @@ static void load_config(void) conf_arp = atoi(opt); else conf_arp = 0; - + if (conf_arp < 0 || conf_arp > 2) { log_error("ipoe: arp=%s: invalid value\n", opt); conf_arp = 0; } - + opt = conf_get_opt("ipoe", "mode"); if (opt) { if (!strcmp(opt, "L2")) @@ -3084,7 +3084,7 @@ static void load_config(void) log_emerg("ipoe: failed to parse 'mode=%s'\n", opt); } else conf_mode = MODE_L2; - + conf_relay = conf_get_opt("ipoe", "relay"); opt = conf_get_opt("ipoe", "relay-timeout"); @@ -3092,25 +3092,25 @@ static void load_config(void) conf_relay_timeout = atoi(opt); else conf_relay_timeout = 3; - + opt = conf_get_opt("ipoe", "relay-retransmit"); if (opt && atoi(opt) > 0) conf_relay_retransmit = atoi(opt); else conf_relay_retransmit = 3; - + opt = conf_get_opt("ipoe", "agent-remote-id"); if (opt) conf_agent_remote_id = opt; else conf_agent_remote_id = "accel-pppd"; - + opt = conf_get_opt("ipoe", "ipv6"); if (opt) conf_ipv6 = atoi(opt); else conf_ipv6 = 0; - + opt = conf_get_opt("ipoe", "noauth"); if (opt) conf_noauth = atoi(opt); @@ -3131,45 +3131,45 @@ static void load_config(void) if (!conf_dhcpv4 && !conf_up) conf_dhcpv4 = 1; - + opt = conf_get_opt("ipoe", "proto"); if (opt && atoi(opt) > 0) conf_proto = atoi(opt); else conf_proto = 3; - + opt = conf_get_opt("ipoe", "vlan-timeout"); if (opt && atoi(opt) > 0) conf_vlan_timeout = atoi(opt); else conf_vlan_timeout = 60; - + opt = conf_get_opt("ipoe", "offer-timeout"); if (opt && atoi(opt) > 0) conf_offer_timeout = atoi(opt); else conf_offer_timeout = 10; - + conf_ip_pool = conf_get_opt("ipoe", "ip-pool"); conf_l4_redirect_pool = conf_get_opt("ipoe", "l4-redirect-ip-pool"); conf_vlan_name = conf_get_opt("ipoe", "vlan-name"); if (!conf_vlan_name) conf_vlan_name = "%I.%N"; - + opt = conf_get_opt("ipoe", "ip-unnumbered"); if (opt) conf_ip_unnumbered = atoi(opt); else conf_ip_unnumbered = 1; - + #ifdef RADIUS if (triton_module_loaded("radius")) load_radius_attrs(); #endif parse_offer_delay(conf_get_opt("ipoe", "offer-delay")); - + load_interfaces(s); load_local_nets(s); load_vlan_mon(s); @@ -3200,7 +3200,7 @@ static void ipoe_init(void) ipset_flush(conf_l4_redirect_ipset); cli_register_simple_cmd2(show_stat_exec, NULL, 2, "show", "stat"); - + triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); #ifdef RADIUS @@ -3209,7 +3209,7 @@ static void ipoe_init(void) triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa); } #endif - + connlimit_loaded = triton_module_loaded("connlimit"); radius_loaded = triton_module_loaded("radius"); } diff --git a/accel-pppd/ctrl/ipoe/ipoe_netlink.c b/accel-pppd/ctrl/ipoe/ipoe_netlink.c index 7643961a..c0610367 100644 --- a/accel-pppd/ctrl/ipoe/ipoe_netlink.c +++ b/accel-pppd/ctrl/ipoe/ipoe_netlink.c @@ -63,7 +63,7 @@ void ipoe_nl_add_net(uint32_t addr, int mask) struct nlmsghdr n; char buf[1024]; } req; - + if (rth.fd == -1) return; @@ -74,7 +74,7 @@ void ipoe_nl_add_net(uint32_t addr, int mask) ghdr = NLMSG_DATA(&req.n); ghdr->cmd = IPOE_CMD_ADD_NET; - + mask = ((1 << mask) - 1) << (32 - mask); addattr32(nlh, 1024, IPOE_ATTR_ADDR, addr); @@ -94,12 +94,12 @@ int ipoe_nl_add_exclude(uint32_t addr, int mask) char buf[1024]; } req; int ret = 0; - + if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) { log_ppp_error("ipoe: cannot open generic netlink socket\n"); return -1; } - + nlh = &req.n; nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; @@ -115,9 +115,9 @@ int ipoe_nl_add_exclude(uint32_t addr, int mask) log_ppp_error("ipoe: nl_add_net: error talking to kernel\n"); ret = -1; } - + rtnl_close(&rth); - + return ret; } @@ -130,7 +130,7 @@ void ipoe_nl_del_exclude(uint32_t addr) struct nlmsghdr n; char buf[1024]; } req; - + if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) { log_ppp_error("ipoe: cannot open generic netlink socket\n"); return; @@ -148,7 +148,7 @@ void ipoe_nl_del_exclude(uint32_t addr) if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) log_ppp_error("ipoe: nl_add_net: error talking to kernel\n"); - + rtnl_close(&rth); } @@ -186,7 +186,7 @@ void ipoe_nl_add_interface(int ifindex) struct nlmsghdr n; char buf[1024]; } req; - + if (rth.fd == -1) return; @@ -238,10 +238,10 @@ int ipoe_nl_create(uint32_t peer_addr, uint32_t addr, const char *ifname, uint8_ if (peer_addr) addattr32(nlh, 1024, IPOE_ATTR_PEER_ADDR, peer_addr); - + if (addr) addattr32(nlh, 1024, IPOE_ATTR_ADDR, addr); - + if (hwaddr) { memcpy(u.hwaddr, hwaddr, 6); addattr_l(nlh, 1024, IPOE_ATTR_HWADDR, &u.u64, 8); @@ -252,7 +252,7 @@ int ipoe_nl_create(uint32_t peer_addr, uint32_t addr, const char *ifname, uint8_ if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) log_ppp_error("ipoe: nl_create: error talking to kernel\n"); - + if (nlh->nlmsg_type != ipoe_genl_id) { log_ppp_error("ipoe: not a IPoE message %d\n", nlh->nlmsg_type); goto out; @@ -281,7 +281,7 @@ int ipoe_nl_create(uint32_t peer_addr, uint32_t addr, const char *ifname, uint8_ } ret = *(uint32_t *)(RTA_DATA(tb[IPOE_ATTR_IFINDEX])); - + out: rtnl_close(&rth); @@ -319,7 +319,7 @@ int ipoe_nl_modify(int ifindex, uint32_t peer_addr, uint32_t addr, const char *i addattr32(nlh, 1024, IPOE_ATTR_IFINDEX, ifindex); addattr32(nlh, 1024, IPOE_ATTR_PEER_ADDR, peer_addr); addattr32(nlh, 1024, IPOE_ATTR_ADDR, addr); - + if (hwaddr) { memcpy(u.hwaddr, hwaddr, 6); addattr_l(nlh, 1024, IPOE_ATTR_HWADDR, &u.u64, 8); @@ -332,7 +332,7 @@ int ipoe_nl_modify(int ifindex, uint32_t peer_addr, uint32_t addr, const char *i log_ppp_error("ipoe: nl_create: error talking to kernel\n"); ret = -1; } - + rtnl_close(&rth); return ret; @@ -399,7 +399,7 @@ void ipoe_nl_get_sessions(struct list_head *list) if (rth.fd == -1) return; - + nlh = &req.n; nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); nlh->nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; @@ -456,7 +456,7 @@ int ipoe_nl_add_vlan_mon(int ifindex, long *mask, int len) struct nlmsghdr n; char buf[1024]; } req; - + if (rth.fd == -1) return -1; @@ -489,12 +489,12 @@ int ipoe_nl_add_vlan_mon_vid(int ifindex, int vid) char buf[1024]; } req; int r = 0; - + if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) { log_error("ipoe: cannot open generic netlink socket\n"); return -1; } - + nlh = &req.n; nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; @@ -510,7 +510,7 @@ int ipoe_nl_add_vlan_mon_vid(int ifindex, int vid) log_error("ipoe: nl_add_vlan_mon_vid: error talking to kernel\n"); r = -1; } - + rtnl_close(&rth); return r; @@ -525,7 +525,7 @@ int ipoe_nl_del_vlan_mon(int ifindex) struct nlmsghdr n; char buf[1024]; } req; - + if (rth.fd == -1) return -1; @@ -575,7 +575,7 @@ static void ipoe_up_handler(const struct sockaddr_nl *addr, struct nlmsghdr *h) break; parse_rtattr_nested(tb2, IPOE_ATTR_MAX, tb[i]); - + if (!tb2[IPOE_ATTR_ETH_HDR] || !tb2[IPOE_ATTR_IP_HDR] || !tb2[IPOE_ATTR_IFINDEX]) continue; @@ -612,7 +612,7 @@ static void ipoe_vlan_mon_handler(const struct sockaddr_nl *addr, struct nlmsghd break; parse_rtattr_nested(tb2, IPOE_ATTR_MAX, tb[i]); - + if (!tb2[IPOE_ATTR_IFINDEX] || !tb2[IPOE_ATTR_ADDR]) continue; @@ -657,7 +657,7 @@ static int ipoe_mc_read(struct triton_md_handler_t *h) continue; return 0; } - + if (status == 0) { log_error("ipoe: EOF on netlink\n"); return 0; @@ -728,13 +728,13 @@ static void init(void) rth.fd = -1; return; } - + if (rtnl_open_byproto(&rth, 1 << (mcg_id - 1), NETLINK_GENERIC)) { log_error("ipoe: cannot open generic netlink socket\n"); rth.fd = -1; return; } - + fcntl(rth.fd, F_SETFL, O_NONBLOCK); fcntl(rth.fd, F_SETFD, fcntl(rth.fd, F_GETFD) | FD_CLOEXEC); diff --git a/accel-pppd/ctrl/ipoe/lua.c b/accel-pppd/ctrl/ipoe/lua.c index 46c85948..abc3d0dd 100644 --- a/accel-pppd/ctrl/ipoe/lua.c +++ b/accel-pppd/ctrl/ipoe/lua.c @@ -70,7 +70,7 @@ static int packet4_hdr(lua_State *L) if (!ses || !ses->dhcpv4_request) return 0; - + if (!strcmp(name, "xid")) lua_pushinteger(L, ses->dhcpv4_request->hdr->xid); else if (!strcmp(name, "ciaddr")) { @@ -95,9 +95,9 @@ static int packet4_ifname(lua_State *L) if (!ses) return 0; - + lua_pushstring(L, ses->serv->ifname); - + return 1; } @@ -129,7 +129,7 @@ static int packet4_options(lua_State *L) if (!ses || !ses->dhcpv4_request) return 0; - + lua_newtable(L); list_for_each_entry(opt, &ses->dhcpv4_request->options, entry) { @@ -146,12 +146,12 @@ static int packet4_agent_circuit_id(lua_State *L) if (!ses || !ses->dhcpv4_request) return 0; - + if (ses->agent_circuit_id) lua_pushlstring(L, (char *)(ses->agent_circuit_id + 1), *ses->agent_circuit_id); else lua_pushnil(L); - + return 1; } @@ -161,12 +161,12 @@ static int packet4_agent_remote_id(lua_State *L) if (!ses || !ses->dhcpv4_request) return 0; - + if (ses->agent_remote_id) lua_pushlstring(L, (char *)(ses->agent_remote_id + 1), *ses->agent_remote_id); else lua_pushnil(L); - + return 1; } @@ -264,7 +264,7 @@ char *ipoe_lua_get_username(struct ipoe_session *ses, const char *func) lua_settop(L, 0); return r; - + out_err: file_error = 1; lua_close(L); diff --git a/accel-pppd/ctrl/ipoe/lua_lpack.c b/accel-pppd/ctrl/ipoe/lua_lpack.c index 0dc3046d..feb0a5a8 100644 --- a/accel-pppd/ctrl/ipoe/lua_lpack.c +++ b/accel-pppd/ctrl/ipoe/lua_lpack.c @@ -109,7 +109,7 @@ static int l_unpack(lua_State *L) /** unpack(s,f,[init]) */ { int c=*f++; int N=1; - if (isdigit(*f)) + if (isdigit(*f)) { N=0; while (isdigit(*f)) N=10*N+(*f++)-'0'; @@ -204,7 +204,7 @@ static int l_pack(lua_State *L) /** pack(f,...) */ { int c=*f++; int N=1; - if (isdigit(*f)) + if (isdigit(*f)) { N=0; while (isdigit(*f)) N=10*N+(*f++)-'0'; diff --git a/accel-pppd/ctrl/l2tp/dict.c b/accel-pppd/ctrl/l2tp/dict.c index f1454499..b636c871 100644 --- a/accel-pppd/ctrl/l2tp/dict.c +++ b/accel-pppd/ctrl/l2tp/dict.c @@ -70,7 +70,7 @@ const struct l2tp_dict_value_t *l2tp_dict_find_value(const struct l2tp_dict_attr static char *skip_word(char *ptr) { for(; *ptr; ptr++) - if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') + if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') break; return ptr; } @@ -91,9 +91,9 @@ static int split(char *buf, char **ptr) buf = skip_word(buf); if (!*buf) return i; - + *buf = 0; - + buf = skip_space(buf + 1); if (!*buf) return i; @@ -153,12 +153,12 @@ static int dict_load(const char *fname) } else if (!strcmp(buf, "ATTRIBUTE")) { if (r < 3) goto out_syntax; - + attr = malloc(sizeof(*attr)); memset(attr, 0, sizeof(*attr)); list_add_tail(&attr->entry, items); INIT_LIST_HEAD(&attr->values); - + attr->name = strdup(ptr[0]); attr->id = strtol(ptr[1], &endptr, 10); if (*endptr != 0) @@ -197,7 +197,7 @@ static int dict_load(const char *fname) } else if (!strcmp(buf, "VALUE")) { if (r != 3) goto out_syntax; - + attr = l2tp_dict_find_attr_by_name(ptr[0]); if (!attr) { log_emerg("l2tp:%s:%i: attribute not found\n", fname, n); diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index 2a52d69f..befe0c90 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -4552,7 +4552,7 @@ static int start_udp_server(void) err_hnd: triton_md_unregister_handler(&udp_serv.hnd, 1); triton_context_unregister(&udp_serv.ctx); - + return -1; err_fd: @@ -4888,7 +4888,7 @@ static void load_config(void) opt = conf_get_opt("l2tp", "dir300_quirk"); if (opt) conf_dir300_quirk = atoi(opt); - + conf_mppe = MPPE_UNSET; opt = conf_get_opt("l2tp", "mppe"); if (opt) { diff --git a/accel-pppd/ctrl/l2tp/netlink.c b/accel-pppd/ctrl/l2tp/netlink.c index c8dce899..3de6e060 100644 --- a/accel-pppd/ctrl/l2tp/netlink.c +++ b/accel-pppd/ctrl/l2tp/netlink.c @@ -11,7 +11,7 @@ void l2tp_nl_delete_tunnel(int tid) { struct nl_sock *nl_sock; struct nl_msg *msg; - + nl_sock = nl_socket_alloc(); msg = nlmsg_alloc(); @@ -32,10 +32,10 @@ void l2tp_nl_create_tunnel(int fd, int tid, int peer_tid) { struct nl_sock *nl_sock; struct nl_msg *msg; - + nl_sock = nl_socket_alloc(); msg = nlmsg_alloc(); - + genl_connect(nl_sock); genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_REQUEST, L2TP_CMD_TUNNEL_CREATE, L2TP_GENL_VERSION); @@ -58,10 +58,10 @@ void l2tp_nl_create_session(int tid, int sid, int peer_sid) { struct nl_sock *nl_sock; struct nl_msg *msg; - + nl_sock = nl_socket_alloc(); msg = nlmsg_alloc(); - + genl_connect(nl_sock); genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_REQUEST, L2TP_CMD_SESSION_CREATE, L2TP_GENL_VERSION); @@ -83,11 +83,11 @@ void l2tp_nl_create_session(int tid, int sid, int peer_sid) static void init(void) { struct nl_sock *nl_sock = nl_socket_alloc(); - + genl_connect(nl_sock); family = genl_ctrl_resolve(nl_sock, L2TP_GENL_NAME); - + nl_close(nl_sock); nl_socket_free(nl_sock); } diff --git a/accel-pppd/ctrl/l2tp/packet.c b/accel-pppd/ctrl/l2tp/packet.c index 78e0789e..34e4bb67 100644 --- a/accel-pppd/ctrl/l2tp/packet.c +++ b/accel-pppd/ctrl/l2tp/packet.c @@ -69,7 +69,7 @@ struct l2tp_packet_t *l2tp_packet_alloc(int ver, int msg_type, struct l2tp_packet_t *pack = mempool_alloc(pack_pool); if (!pack) return NULL; - + memset(pack, 0, sizeof(*pack)); INIT_LIST_HEAD(&pack->attrs); pack->hdr.ver = ver; @@ -250,16 +250,16 @@ int l2tp_recv(int fd, struct l2tp_packet_t **p, struct in_pktinfo *pkt_info, memset(&msg, 0, sizeof(msg)); msg.msg_control = msg_control; msg.msg_controllen = 128; - + n = recvmsg(fd, &msg, MSG_PEEK); - + if (n < 0) { if (errno == EAGAIN) return -1; log_error("l2tp: recvmsg: %s\n", strerror(errno)); return 0; } - + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) { if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO) { memcpy(pkt_info, CMSG_DATA(cmsg), sizeof(*pkt_info)); diff --git a/accel-pppd/ctrl/pppoe/cli.c b/accel-pppd/ctrl/pppoe/cli.c index ad577c11..c79a5f1e 100644 --- a/accel-pppd/ctrl/pppoe/cli.c +++ b/accel-pppd/ctrl/pppoe/cli.c @@ -77,7 +77,7 @@ static int intf_exec(const char *cmd, char * const *fields, int fields_cnt, void pppoe_server_stop(fields[3]); else goto help; - + return CLI_CMD_OK; help: intf_help(fields, fields_cnt, client); @@ -149,9 +149,9 @@ static int show_verbose_exec(const char *cmd, char * const *f, int f_cnt, void * { if (f_cnt != 3) return CLI_CMD_SYNTAX; - + cli_sendv(cli, "%i\r\n", conf_verbose); - + return CLI_CMD_OK; } @@ -159,9 +159,9 @@ static int show_pado_delay_exec(const char *cmd, char * const *f, int f_cnt, voi { if (f_cnt != 3) return CLI_CMD_SYNTAX; - + cli_sendv(cli, "%s\r\n", conf_pado_delay); - + return CLI_CMD_OK; } @@ -169,12 +169,12 @@ static int show_service_name_exec(const char *cmd, char * const *f, int f_cnt, v { if (f_cnt != 3) return CLI_CMD_SYNTAX; - + if (conf_service_name) cli_sendv(cli, "%s\r\n", conf_service_name); else cli_sendv(cli, "*\r\n"); - + return CLI_CMD_OK; } @@ -182,9 +182,9 @@ static int show_ac_name_exec(const char *cmd, char * const *f, int f_cnt, void * { if (f_cnt != 3) return CLI_CMD_SYNTAX; - + cli_sendv(cli, "%s\r\n", conf_ac_name); - + return CLI_CMD_OK; } @@ -192,14 +192,14 @@ static int set_verbose_exec(const char *cmd, char * const *f, int f_cnt, void *c { if (f_cnt != 4) return CLI_CMD_SYNTAX; - + if (!strcmp(f[3], "0")) conf_verbose = 0; else if (!strcmp(f[3], "1")) conf_verbose = 1; else return CLI_CMD_INVAL; - + return CLI_CMD_OK; } @@ -218,7 +218,7 @@ static int set_service_name_exec(const char *cmd, char * const *f, int f_cnt, vo { if (f_cnt != 4) return CLI_CMD_SYNTAX; - + if (conf_service_name) _free(conf_service_name); @@ -226,7 +226,7 @@ static int set_service_name_exec(const char *cmd, char * const *f, int f_cnt, vo conf_service_name = NULL; else conf_service_name = _strdup(f[3]); - + return CLI_CMD_OK; } @@ -234,10 +234,10 @@ static int set_ac_name_exec(const char *cmd, char * const *f, int f_cnt, void *c { if (f_cnt != 4) return CLI_CMD_SYNTAX; - + _free(conf_ac_name); conf_ac_name = _strdup(f[3]); - + return CLI_CMD_OK; } //=================================== diff --git a/accel-pppd/ctrl/pppoe/dpado.c b/accel-pppd/ctrl/pppoe/dpado.c index 3f565198..c7992bc4 100644 --- a/accel-pppd/ctrl/pppoe/dpado.c +++ b/accel-pppd/ctrl/pppoe/dpado.c @@ -37,7 +37,7 @@ void dpado_check_next(int conn_cnt) dpado_range_next = list_entry(dpado_range_next->entry.next, typeof(*dpado_range_next), entry); else dpado_range_next = NULL; - /*printf("active=%i, prev=%i:%i, next=%i:%i, pado_delay=%i\n", stat_active, + /*printf("active=%i, prev=%i:%i, next=%i:%i, pado_delay=%i\n", stat_active, dpado_range_prev?dpado_range_prev->pado_delay:0,dpado_range_prev?dpado_range_prev->conn_cnt:0, dpado_range_next?dpado_range_next->pado_delay:0,dpado_range_next?dpado_range_next->conn_cnt:0, pado_delay);*/ @@ -52,7 +52,7 @@ void dpado_check_prev(int conn_cnt) dpado_range_next = dpado_range_prev; dpado_range_prev = list_entry(dpado_range_prev->entry.prev, typeof(*dpado_range_prev), entry); pado_delay = dpado_range_prev->pado_delay; - /*printf("active=%i, prev=%i:%i, next=%i:%i, pado_delay=%i\n", stat_active, + /*printf("active=%i, prev=%i:%i, next=%i:%i, pado_delay=%i\n", stat_active, dpado_range_prev?dpado_range_prev->pado_delay:0,dpado_range_prev?dpado_range_prev->conn_cnt:0, dpado_range_next?dpado_range_next->pado_delay:0,dpado_range_next?dpado_range_next->conn_cnt:0, pado_delay);*/ @@ -144,7 +144,7 @@ int dpado_parse(const char *str) if (conf_pado_delay) _free(conf_pado_delay); conf_pado_delay = _strdup(str); - /*printf("active=%i, prev=%i:%i, next=%i:%i, pado_delay=%i\n", stat_active, + /*printf("active=%i, prev=%i:%i, next=%i:%i, pado_delay=%i\n", stat_active, dpado_range_prev?dpado_range_prev->pado_delay:0,dpado_range_prev?dpado_range_prev->conn_cnt:0, dpado_range_next?dpado_range_next->pado_delay:0,dpado_range_next?dpado_range_next->conn_cnt:0, pado_delay);*/ diff --git a/accel-pppd/ctrl/pppoe/mac_filter.c b/accel-pppd/ctrl/pppoe/mac_filter.c index b55cbf2e..d1e104e6 100644 --- a/accel-pppd/ctrl/pppoe/mac_filter.c +++ b/accel-pppd/ctrl/pppoe/mac_filter.c @@ -73,7 +73,7 @@ static int mac_filter_load(const char *opt) log_emerg("pppoe: open '%s': %s\n", name, strerror(errno)); goto err; } - + conf_mac_filter = opt; pthread_rwlock_wrlock(&lock); @@ -274,7 +274,7 @@ static void init(void) const char *opt = conf_get_opt("pppoe", "mac-filter"); if (!opt || mac_filter_load(opt)) type = -1; - + cli_register_simple_cmd2(cmd_exec, cmd_help, 2, "pppoe", "mac-filter"); } diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index 5037f5a0..12c274bb 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -49,7 +49,7 @@ struct pppoe_conn_t { struct pppoe_tag *service_name; struct pppoe_tag *tr101; uint8_t cookie[COOKIE_LENGTH - 4]; - + struct ap_ctrl ctrl; struct ppp_t ppp; #ifdef RADIUS @@ -153,7 +153,7 @@ static void disconnect(struct pppoe_conn_t *conn) pppoe_server_free(conn->serv); } else pthread_mutex_unlock(&conn->serv->lock); - + pthread_mutex_lock(&sid_lock); sid_map[conn->sid/(8*sizeof(long))] |= 1 << (conn->sid % (8*sizeof(long))); pthread_mutex_unlock(&sid_lock); @@ -209,7 +209,7 @@ static int pppoe_rad_send_access_request(struct rad_plugin_t *rad, struct rad_pa if (conn->tr101) return tr101_send_access_request(conn->tr101, pack); - + return 0; } @@ -219,11 +219,11 @@ static int pppoe_rad_send_accounting_request(struct rad_plugin_t *rad, struct ra if (conn->tr101) return tr101_send_accounting_request(conn->tr101, pack); - + return 0; } #endif - + static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const uint8_t *addr, const struct pppoe_tag *host_uniq, const struct pppoe_tag *relay_sid, const struct pppoe_tag *service_name, const struct pppoe_tag *tr101, const uint8_t *cookie) { struct pppoe_conn_t *conn; @@ -241,18 +241,18 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui old_sid_ptr = sid_ptr; while (1) { int bit = ffsl(*sid_ptr) - 1; - + if (bit != -1) { conn->sid = sid_idx*8*sizeof(long) + bit; *sid_ptr &= ~(1lu << bit); } - + if (++sid_idx == SID_MAX/8/sizeof(long)) { sid_ptr = sid_map; sid_idx = 0; } else sid_ptr++; - + if (bit != -1) break; @@ -349,7 +349,7 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui else sprintf(conn->ctrl.calling_station_id, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); - + ppp_init(&conn->ppp); conn->ppp.ses.ctrl = &conn->ctrl; @@ -357,16 +357,16 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui if (conf_ip_pool) conn->ppp.ses.ipv4_pool_name = _strdup(conf_ip_pool); - + conn->disc_sock = dup(serv->hnd.fd); - + triton_context_register(&conn->ctx, &conn->ppp.ses); pthread_mutex_lock(&serv->lock); list_add_tail(&conn->entry, &serv->conn_list); serv->conn_cnt++; pthread_mutex_unlock(&serv->lock); - + return conn; } @@ -374,7 +374,7 @@ static void connect_channel(struct pppoe_conn_t *conn) { int sock; struct sockaddr_pppox sp; - + triton_event_fire(EV_CTRL_STARTING, &conn->ppp.ses); triton_event_fire(EV_CTRL_STARTED, &conn->ppp.ses); @@ -383,7 +383,7 @@ static void connect_channel(struct pppoe_conn_t *conn) log_error("pppoe: socket(PPPOX): %s\n", strerror(errno)); goto out_err; } - + fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC); memset(&sp, 0, sizeof(sp)); @@ -403,7 +403,7 @@ static void connect_channel(struct pppoe_conn_t *conn) if (establish_ppp(&conn->ppp)) goto out_err_close; - + #ifdef RADIUS if (conn->tr101 && triton_module_loaded("radius")) { conn->radius.send_access_request = pppoe_rad_send_access_request; @@ -413,9 +413,9 @@ static void connect_channel(struct pppoe_conn_t *conn) #endif conn->ppp_started = 1; - + dpado_check_next(__sync_add_and_fetch(&stat_active, 1)); - + return; out_err_close: @@ -478,8 +478,8 @@ static void print_packet(uint8_t *pack) log_info2("PADT"); break; } - - log_info2(" %02x:%02x:%02x:%02x:%02x:%02x => %02x:%02x:%02x:%02x:%02x:%02x", + + log_info2(" %02x:%02x:%02x:%02x:%02x:%02x => %02x:%02x:%02x:%02x:%02x:%02x", ethhdr->h_source[0], ethhdr->h_source[1], ethhdr->h_source[2], ethhdr->h_source[3], ethhdr->h_source[4], ethhdr->h_source[5], ethhdr->h_dest[0], ethhdr->h_dest[1], ethhdr->h_dest[2], ethhdr->h_dest[3], ethhdr->h_dest[4], ethhdr->h_dest[5]); @@ -577,7 +577,7 @@ static void generate_cookie(struct pppoe_serv_t *serv, const uint8_t *src, uint8 u1.raw[16 + i] = buf[i] ^ buf[i + 4] ^ buf[i + 8] ^ buf[i + 12]; } else memset(u1.raw + 16, 0, 4); - + *(uint32_t *)(u1.raw + 20) = ts.tv_sec + conf_cookie_timeout; for (i = 0; i < 3; i++) @@ -585,7 +585,7 @@ static void generate_cookie(struct pppoe_serv_t *serv, const uint8_t *src, uint8 for (i = 0; i < 3; i++) DES_ecb_encrypt(&u2.b[i], &u1.b[i], &serv->des_ks, DES_ENCRYPT); - + memcpy(cookie, u1.raw, 24); } @@ -593,7 +593,7 @@ static int check_cookie(struct pppoe_serv_t *serv, const uint8_t *src, const uin { MD5_CTX ctx; DES_cblock key; - DES_key_schedule ks; + DES_key_schedule ks; int i; union { DES_cblock b[3]; @@ -602,7 +602,7 @@ static int check_cookie(struct pppoe_serv_t *serv, const uint8_t *src, const uin struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - + memcpy(key, serv->hwaddr, 6); key[6] = src[4]; key[7] = src[5]; @@ -612,13 +612,13 @@ static int check_cookie(struct pppoe_serv_t *serv, const uint8_t *src, const uin for (i = 0; i < 3; i++) DES_ecb_encrypt(&u1.b[i], &u2.b[i], &serv->des_ks, DES_DECRYPT); - + for (i = 0; i < 3; i++) DES_ecb_encrypt(&u2.b[i], &u1.b[i], &ks, DES_DECRYPT); - + if (*(uint32_t *)(u1.raw + 20) < ts.tv_sec) return 1; - + MD5_Init(&ctx); MD5_Update(&ctx, serv->secret, SECRET_LENGTH); MD5_Update(&ctx, serv->hwaddr, ETH_ALEN); @@ -664,7 +664,7 @@ static void add_tag2(uint8_t *pack, const struct pppoe_tag *t) struct pppoe_tag *tag = (struct pppoe_tag *)(pack + ETH_HLEN + sizeof(*hdr) + ntohs(hdr->length)); memcpy(tag, t, sizeof(*t) + ntohs(t->tag_len)); - + hdr->length = htons(ntohs(hdr->length) + sizeof(*tag) + ntohs(t->tag_len)); } @@ -695,14 +695,14 @@ static void pppoe_send_PADO(struct pppoe_serv_t *serv, const uint8_t *addr, cons if (service_name) add_tag2(pack, service_name); - + generate_cookie(serv, addr, cookie, host_uniq, relay_sid); add_tag(pack, TAG_AC_COOKIE, cookie, COOKIE_LENGTH); if (host_uniq) add_tag2(pack, host_uniq); - + if (relay_sid) add_tag2(pack, relay_sid); @@ -726,7 +726,7 @@ static void pppoe_send_err(struct pppoe_serv_t *serv, const uint8_t *addr, const if (host_uniq) add_tag2(pack, host_uniq); - + if (relay_sid) add_tag2(pack, relay_sid); @@ -745,12 +745,12 @@ static void pppoe_send_PADS(struct pppoe_conn_t *conn) setup_header(pack, conn->serv->hwaddr, conn->addr, CODE_PADS, conn->sid); add_tag(pack, TAG_AC_NAME, (uint8_t *)conf_ac_name, strlen(conf_ac_name)); - + add_tag2(pack, conn->service_name); if (conn->host_uniq) add_tag2(pack, conn->host_uniq); - + if (conn->relay_sid) add_tag2(pack, conn->relay_sid); @@ -831,13 +831,13 @@ static int check_padi_limit(struct pppoe_serv_t *serv, uint8_t *addr) } else break; } - + if (serv->padi_cnt == serv->padi_limit) return -1; - + if (conf_padi_limit && total_padi_cnt >= conf_padi_limit) return -1; - + list_for_each_entry(padi, &serv->padi_list, entry) { if (memcmp(padi->addr, addr, ETH_ALEN) == 0) return -1; @@ -846,7 +846,7 @@ static int check_padi_limit(struct pppoe_serv_t *serv, uint8_t *addr) padi = mempool_alloc(padi_pool); if (!padi) return -1; - + padi->ts = ts; memcpy(padi->addr, addr, ETH_ALEN); list_add_tail(&padi->entry, &serv->padi_list); @@ -990,13 +990,13 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size) if (ap_shutdown) return; - + if (!memcmp(ethhdr->h_dest, bc_addr, ETH_ALEN)) { if (conf_verbose) log_warn("pppoe: discard PADR (destination address is broadcast)\n"); return; } - + if (hdr->sid) { if (conf_verbose) log_warn("pppoe: discarding PADR packet (sid is not zero)\n"); @@ -1007,7 +1007,7 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size) log_info2("recv "); print_packet(pack); } - + for (n = 0; n < ntohs(hdr->length); n += sizeof(*tag) + ntohs(tag->tag_len)) { tag = (struct pppoe_tag *)(pack + ETH_HLEN + sizeof(*hdr) + n); @@ -1110,13 +1110,13 @@ static void pppoe_recv_PADT(struct pppoe_serv_t *serv, uint8_t *pack) struct pppoe_hdr *hdr = (struct pppoe_hdr *)(pack + ETH_HLEN); struct pppoe_conn_t *conn; uint16_t sid = ntohs(hdr->sid); - + if (!memcmp(ethhdr->h_dest, bc_addr, ETH_ALEN)) { if (conf_verbose) log_warn("pppoe: discard PADT (destination address is broadcast)\n"); return; } - + if (conf_verbose) { log_info2("recv "); print_packet(pack); @@ -1191,7 +1191,7 @@ static int pppoe_serv_read(struct triton_md_handler_t *h) log_warn("pppoe: discarding packet (unsupported version %i)\n", hdr->ver); continue; } - + if (hdr->type != 1) { if (conf_verbose) log_warn("pppoe: discarding packet (unsupported type %i)\n", hdr->type); @@ -1266,13 +1266,13 @@ static void pppoe_add_interface_re(const char *opt, void *cli) struct iplink_arg arg; for (ptr = opt; *ptr && *ptr != ','; ptr++); - + pattern = _malloc(ptr - (opt + 3) + 1); memcpy(pattern, opt + 3, ptr - (opt + 3)); pattern[ptr - (opt + 3)] = 0; - + re = pcre_compile2(pattern, 0, NULL, &pcre_err, &pcre_offset, NULL); - + if (!re) { log_error("pppoe: %s at %i\r\n", pcre_err, pcre_offset); return; @@ -1352,7 +1352,7 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli) _free(serv); return; } - + fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC); if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &f, sizeof(f))) { @@ -1398,7 +1398,7 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli) cli_sendv(cli, "interface %s has MTU of %i, should be %i\r\n", ifname, ifr.ifr_mtu, ETH_DATA_LEN); log_error("pppoe: interface %s has MTU of %i, should be %i\n", ifname, ifr.ifr_mtu, ETH_DATA_LEN); } - + if (ioctl(sock, SIOCGIFINDEX, &ifr)) { if (cli) cli_sendv(cli, "ioctl(SIOCGIFINDEX): %s\r\n", strerror(errno)); @@ -1464,7 +1464,7 @@ static void _server_stop(struct pppoe_serv_t *serv) if (serv->stopping) return; - + serv->stopping = 1; triton_md_disable_handler(&serv->hnd, MD_MODE_READ | MD_MODE_WRITE); @@ -1578,11 +1578,11 @@ static void load_config(void) opt = conf_get_opt("pppoe", "PADO-Delay"); if (opt) dpado_parse(opt); - + opt = conf_get_opt("pppoe", "tr101"); if (opt) conf_tr101 = atoi(opt); - + opt = conf_get_opt("pppoe", "padi-limit"); if (opt) conf_padi_limit = atoi(opt); @@ -1590,7 +1590,7 @@ static void load_config(void) opt = conf_get_opt("pppoe", "sid-uppercase"); if (opt) conf_sid_uppercase = atoi(opt); - + opt = conf_get_opt("pppoe", "cookie-timeout"); if (opt) conf_cookie_timeout = atoi(opt); @@ -1665,7 +1665,7 @@ static void pppoe_init(void) log_error("pppoe: no configuration, disabled...\n"); return; } - + load_config(); connlimit_loaded = triton_module_loaded("connlimit"); diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c index 19deb3db..94cfd7fd 100644 --- a/accel-pppd/ctrl/pptp/pptp.c +++ b/accel-pppd/ctrl/pptp/pptp.c @@ -78,7 +78,7 @@ static void disconnect(struct pptp_conn_t *conn) log_ppp_debug("pptp: disconnect\n"); triton_md_unregister_handler(&conn->hnd, 1); - + if (conn->timeout_timer.tpd) triton_timer_del(&conn->timeout_timer); @@ -93,14 +93,14 @@ static void disconnect(struct pptp_conn_t *conn) __sync_sub_and_fetch(&stat_starting, 1); triton_event_fire(EV_CTRL_FINISHED, &conn->ppp.ses); - + log_ppp_info1("disconnected\n"); triton_context_unregister(&conn->ctx); if (conn->ppp.ses.chan_name) _free(conn->ppp.ses.chan_name); - + _free(conn->in_buf); _free(conn->out_buf); _free(conn->ctrl.calling_station_id); @@ -178,7 +178,7 @@ static int pptp_stop_ctrl_conn_rqst(struct pptp_conn_t *conn) } static int pptp_stop_ctrl_conn_rply(struct pptp_conn_t *conn) -{ +{ struct pptp_stop_ctrl_conn *msg = (struct pptp_stop_ctrl_conn*)conn->in_buf; if (conf_verbose) log_ppp_info2("recv [PPTP Stop-Ctrl-Conn-Reply <Result %i> <Error %i>]\n", msg->reason_result, msg->error_code); @@ -342,7 +342,7 @@ static int pptp_out_call_rqst(struct pptp_conn_t *conn) conn->state = STATE_PPP; __sync_sub_and_fetch(&stat_starting, 1); __sync_add_and_fetch(&stat_active, 1); - + if (conn->timeout_timer.tpd) triton_timer_del(&conn->timeout_timer); @@ -366,7 +366,7 @@ static int send_pptp_call_disconnect_notify(struct pptp_conn_t *conn, int result if (conf_verbose) log_ppp_info2("send [PPTP Call-Disconnect-Notify <Call-ID %x> <Result %i> <Error %i> <Cause %i>]\n", ntohs(msg.call_id), msg.result_code, msg.error_code, msg.cause_code); - + return post_msg(conn, &msg, sizeof(msg)); } @@ -409,7 +409,7 @@ static int pptp_echo_rqst(struct pptp_conn_t *conn) static int pptp_echo_rply(struct pptp_conn_t *conn) { struct pptp_echo_rply *msg = (struct pptp_echo_rply *)conn->in_buf; - + if (conf_verbose) log_ppp_debug("recv [PPTP Echo-Reply <Identifier %x>]\n", msg->identifier); @@ -678,13 +678,13 @@ static int pptp_connect(struct triton_md_handler_t *h) conn->ctrl.ppp = 1; conn->ctrl.name = "pptp"; conn->ctrl.mppe = conf_mppe; - + conn->ctrl.calling_station_id = _malloc(17); conn->ctrl.called_station_id = _malloc(17); u_inet_ntoa(addr.sin_addr.s_addr, conn->ctrl.calling_station_id); getsockname(sock, &addr, &size); u_inet_ntoa(addr.sin_addr.s_addr, conn->ctrl.called_station_id); - + ppp_init(&conn->ppp); conn->ppp.ses.ctrl = &conn->ctrl; @@ -739,7 +739,7 @@ static void load_config(void) opt = conf_get_opt("pptp", "timeout"); if (opt && atoi(opt) > 0) conf_timeout = atoi(opt); - + opt = conf_get_opt("pptp", "echo-interval"); if (opt && atoi(opt) >= 0) conf_echo_interval = atoi(opt); @@ -787,7 +787,7 @@ static void pptp_init(void) } fcntl(serv.hnd.fd, F_SETFD, fcntl(serv.hnd.fd, F_GETFD) | FD_CLOEXEC); - + addr.sin_family = AF_INET; opt = conf_get_opt("pptp", "bind"); @@ -801,8 +801,8 @@ static void pptp_init(void) addr.sin_port = htons(atoi(opt)); else addr.sin_port = htons(PPTP_PORT); - - setsockopt(serv.hnd.fd, SOL_SOCKET, SO_REUSEADDR, &serv.hnd.fd, 4); + + setsockopt(serv.hnd.fd, SOL_SOCKET, SO_REUSEADDR, &serv.hnd.fd, 4); if (bind (serv.hnd.fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) { log_emerg("pptp: failed to bind socket: %s\n", strerror(errno)); close(serv.hnd.fd); @@ -820,7 +820,7 @@ static void pptp_init(void) close(serv.hnd.fd); return; } - + conn_pool = mempool_create(sizeof(struct pptp_conn_t)); load_config(); @@ -831,7 +831,7 @@ static void pptp_init(void) triton_context_wakeup(&serv.ctx); cli_register_simple_cmd2(show_stat_exec, NULL, 2, "show", "stat"); - + triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); } diff --git a/accel-pppd/extra/chap-secrets.c b/accel-pppd/extra/chap-secrets.c index d48ecf6b..b693a326 100644 --- a/accel-pppd/extra/chap-secrets.c +++ b/accel-pppd/extra/chap-secrets.c @@ -71,7 +71,7 @@ static char *skip_word(char *ptr) *ptr = ' '; break; } - } else if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') + } else if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') break; } @@ -95,9 +95,9 @@ static int split(char *buf, char **ptr) buf = skip_word(buf); if (!*buf) return i; - + *buf = 0; - + buf = skip_space(buf + 1); if (!*buf) return i; @@ -135,7 +135,7 @@ static struct cs_pd_t *create_pd(struct ap_session *ses, const char *username) if (!conf_chap_secrets) return NULL; - + #ifdef CRYPTO_OPENSSL if (conf_encrypted && !list_empty(&hash_chain)) { unsigned int size = 0; @@ -153,7 +153,7 @@ static struct cs_pd_t *create_pd(struct ap_session *ses, const char *username) username = username_hash; } #endif - + f = fopen(conf_chap_secrets, "r"); if (!f) { log_error("chap-secrets: open '%s': %s\n", conf_chap_secrets, strerror(errno)); @@ -166,7 +166,7 @@ static struct cs_pd_t *create_pd(struct ap_session *ses, const char *username) fclose(f); return NULL; } - + while (fgets(buf, 4096, f)) { if (buf[0] == '#') continue; @@ -209,14 +209,14 @@ found: _free(pd); goto out; } - + for (i = 0; i < 16; i++) { c = ptr[1][i*2 + 2]; ptr[1][i*2 + 2] = 0; pd->passwd[i] = strtol(ptr[1] + i*2, NULL, 16); ptr[1][i*2 + 2] = c; } - } else + } else #endif { pd->passwd = _strdup(ptr[1]); @@ -290,7 +290,7 @@ static void ev_ses_pre_up(struct ap_session *ses) static struct ipv4db_item_t *get_ip(struct ap_session *ses) { struct cs_pd_t *pd; - + if (!conf_gw_ip_address && ses->ctrl->ppp) return NULL; @@ -319,10 +319,10 @@ static char* get_passwd(struct pwdb_t *pwdb, struct ap_session *ses, const char if (!pd) pd = create_pd(ses, username); - + if (!pd) return NULL; - + return _strdup(pd->passwd); } @@ -353,7 +353,7 @@ static void des_encrypt(const uint8_t *input, const uint8_t *key, uint8_t *outpu DES_set_key_checked(&cb, &ks); memcpy(cb, input, 8); DES_ecb_encrypt(&cb, &res, &ks, DES_ENCRYPT); - memcpy(output, res, 8); + memcpy(output, res, 8); } static int auth_pap(struct cs_pd_t *pd, const char *username, va_list args) @@ -363,7 +363,7 @@ static int auth_pap(struct cs_pd_t *pd, const char *username, va_list args) unsigned char z_hash[21]; char *u_passwd; int i, len = strlen(passwd); - + u_passwd = _malloc(len * 2); for (i = 0; i< len; i++) { u_passwd[i * 2] = passwd[i]; @@ -380,10 +380,10 @@ static int auth_pap(struct cs_pd_t *pd, const char *username, va_list args) /*des_encrypt(ad->val, z_hash, nt_hash); des_encrypt(ad->val, z_hash + 7, nt_hash + 8); des_encrypt(ad->val, z_hash + 14, nt_hash + 16);*/ - + if (memcmp(z_hash, pd->passwd, 16)) return PWDB_DENIED; - + return PWDB_SUCCESS; } @@ -421,7 +421,7 @@ static void derive_mppe_keys_mschap_v1(struct ap_session *ses, const uint8_t *z_ SHA1_Update(&sha_ctx, digest, 16); SHA1_Update(&sha_ctx, digest, 16); SHA1_Update(&sha_ctx, challenge, challenge_len); - SHA1_Final(digest, &sha_ctx); + SHA1_Final(digest, &sha_ctx); triton_event_fire(EV_MPPE_KEYS, &ev_mppe); } @@ -439,7 +439,7 @@ int auth_mschap_v1(struct ap_session *ses, struct cs_pd_t *pd, const char *usern memcpy(z_hash, pd->passwd, 16); memset(z_hash + 16, 0, sizeof(z_hash) - 16); - + des_encrypt(challenge, z_hash, nt_hash); des_encrypt(challenge, z_hash + 7, nt_hash + 8); des_encrypt(challenge, z_hash + 14, nt_hash + 16); @@ -460,7 +460,7 @@ static void generate_mschap_response(const uint8_t *nt_response, const uint8_t * uint8_t pw_hash[MD4_DIGEST_LENGTH]; uint8_t response[SHA_DIGEST_LENGTH]; int i; - + uint8_t magic1[39] = {0x4D, 0x61, 0x67, 0x69, 0x63, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x74, 0x6F, 0x20, 0x63, 0x6C, 0x69, 0x65, @@ -489,7 +489,7 @@ static void generate_mschap_response(const uint8_t *nt_response, const uint8_t * SHA1_Update(&sha_ctx, c_hash, 8); SHA1_Update(&sha_ctx, magic2, 41); SHA1_Final(response, &sha_ctx); - + for (i = 0; i < 20; i++) sprintf(authenticator + i*2, "%02X", response[i]); } @@ -502,7 +502,7 @@ static void derive_mppe_keys_mschap_v2(struct ap_session *ses, const uint8_t *z_ uint8_t digest[20]; uint8_t send_key[20]; uint8_t recv_key[20]; - + uint8_t pad1[40] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -548,7 +548,7 @@ static void derive_mppe_keys_mschap_v2(struct ap_session *ses, const uint8_t *z_ .recv_key = recv_key, .send_key = send_key, }; - + //NtPasswordHashHash MD4_Init(&md4_ctx); MD4_Update(&md4_ctx, z_hash, 16); @@ -602,7 +602,7 @@ int auth_mschap_v2(struct ap_session *ses, struct cs_pd_t *pd, const char *usern memcpy(z_hash, pd->passwd, 16); memset(z_hash + 16, 0, sizeof(z_hash) - 16); - + des_encrypt(c_hash, z_hash, nt_hash); des_encrypt(c_hash, z_hash + 7, nt_hash + 8); des_encrypt(c_hash, z_hash + 14, nt_hash + 16); @@ -613,7 +613,7 @@ int auth_mschap_v2(struct ap_session *ses, struct cs_pd_t *pd, const char *usern if (ses->ctrl->ppp) derive_mppe_keys_mschap_v2(ses, z_hash, response); - generate_mschap_response(response, c_hash, z_hash, authenticator); + generate_mschap_response(response, c_hash, z_hash, authenticator); return PWDB_SUCCESS; } @@ -626,7 +626,7 @@ static int check_passwd(struct pwdb_t *pwdb, struct ap_session *ses, pwdb_callba if (!conf_encrypted) return PWDB_NO_IMPL; - + pd = find_pd(ses); if (!pd) @@ -634,7 +634,7 @@ static int check_passwd(struct pwdb_t *pwdb, struct ap_session *ses, pwdb_callba if (!pd) return PWDB_NO_IMPL; - + va_copy(args, _args); switch (type) { @@ -656,7 +656,7 @@ static int check_passwd(struct pwdb_t *pwdb, struct ap_session *ses, pwdb_callba } break; } - + va_end(args); return r; @@ -692,7 +692,7 @@ static void parse_hash_chain(const char *opt) char *ptr1 = str, *ptr2; struct hash_chain *hc; int f = 0; - + while (!f) { for (ptr2 = ptr1 + 1; *ptr2 && *ptr2 != ','; ptr2++); f = *ptr2 == 0; @@ -748,13 +748,13 @@ static void load_config(void) else { conf_gw_ip_address = 0; } - + opt = conf_get_opt("chap-secrets", "encrypted"); if (opt) conf_encrypted = atoi(opt); else conf_encrypted = 0; - + #ifdef CRYPTO_OPENSSL clear_hash_chain(); opt = conf_get_opt("chap-secrets", "username-hash"); @@ -769,7 +769,7 @@ static void init(void) pwdb_register(&pwdb); ipdb_register(&ipdb); - + triton_event_register_handler(EV_SES_FINISHED, (triton_event_func)ev_ses_finished); triton_event_register_handler(EV_SES_PRE_UP, (triton_event_func)ev_ses_pre_up); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); diff --git a/accel-pppd/extra/connlimit.c b/accel-pppd/extra/connlimit.c index fd7c952b..49871dd8 100644 --- a/accel-pppd/extra/connlimit.c +++ b/accel-pppd/extra/connlimit.c @@ -35,7 +35,7 @@ int __export connlimit_check(uint64_t key) LIST_HEAD(tmp_list); int r = 1; - + clock_gettime(CLOCK_MONOTONIC, &ts); pthread_mutex_lock(&lock); @@ -87,13 +87,13 @@ int __export connlimit_check(uint64_t key) r = 0; } - + if (r == 0) log_debug("connlimit: accept %" PRIu64 "\n", key); else log_debug("connlimit: drop %" PRIu64 "\n", key); - + while (!list_empty(&tmp_list)) { it = list_entry(tmp_list.next, typeof(*it), entry); list_del(&it->entry); @@ -113,10 +113,10 @@ static int parse_limit(const char *opt, int *limit, int *time) *time = 1; return 0; } - + if (*endptr != '/') goto out_err; - + opt = endptr + 1; *time = strtol(opt, &endptr, 10); @@ -125,18 +125,18 @@ static int parse_limit(const char *opt, int *limit, int *time) if (*endptr == 's') return 0; - + if (*endptr == 'm') { *time *= 60; return 0; } - + if (*endptr == 'h') { *time *= 3600; return 0; } - -out_err: + +out_err: log_error("connlimit: failed to parse '%s'\n", opt); return -1; } @@ -156,7 +156,7 @@ static void load_config() opt = conf_get_opt("connlimit", "burst"); if (opt) conf_burst = atoi(opt); - + opt = conf_get_opt("connlimit", "timeout"); if (opt) conf_burst_timeout = atoi(opt) * 1000; diff --git a/accel-pppd/extra/ippool.c b/accel-pppd/extra/ippool.c index 15238025..c192e8d4 100644 --- a/accel-pppd/extra/ippool.c +++ b/accel-pppd/extra/ippool.c @@ -87,7 +87,7 @@ struct ippool_t *find_pool(const char *name, int create) if (create) return create_pool(name); - + return NULL; } @@ -95,7 +95,7 @@ static void parse_gw_ip_address(const char *val) { if (!val) return; - + conf_gw_ip_address = inet_addr(val); } @@ -103,7 +103,7 @@ static void parse_gw_ip_address(const char *val) static int parse1(const char *str, uint32_t *begin, uint32_t *end) { int n, f1, f2, f3, f4, m, mask = 0; - + n = sscanf(str, "%u.%u.%u.%u/%u",&f1, &f2, &f3, &f4, &m); if (n != 5) return -1; @@ -117,7 +117,7 @@ static int parse1(const char *str, uint32_t *begin, uint32_t *end) return -1; if (m == 0 || m > 32) return -1; - + *begin = (f4 << 24) | (f3 << 16) | (f2 << 8) | f1; mask = htonl(~((1 << (32 - m)) - 1)); @@ -145,7 +145,7 @@ static int parse2(const char *str, uint32_t *begin, uint32_t *end) return -1; if (m < f4 || m > 255) return -1; - + *begin = ntohl((f4 << 24) | (f3 << 16) | (f2 << 8) | f1); *end = ntohl((m << 24) | (f3 << 16) | (f2 << 8) | f1); @@ -184,12 +184,12 @@ static uint8_t get_random() if (pos == 0) read(urandom_fd, buf, 128); - + r = buf[pos++]; if (pos == 128) pos = 0; - + return r; } @@ -224,17 +224,17 @@ static void generate_pool_p2p(struct ippool_t *p) pos1 = pos1->next; pos2 = pos2->prev; - + if (r >= 64) continue; - + peer_addr = list_entry(pos, typeof(*peer_addr), entry); if (pos == pos1) pos1 = pos1->next; - + if (pos == pos2) pos2 = pos2->prev; - + list_del(&peer_addr->entry); t = 0; } else { @@ -304,13 +304,13 @@ static void generate_pool_net30(struct ippool_t *p) it->it.peer_addr = addr[2]->addr; list_add_tail(&it->entry, &p->items); - + for (i = 0; i < 4; i++) { if (addr[i]) free(addr[i]); } } - + for (i = 0; i < 4; i++) { if (addr[i]) free(addr[i]); @@ -514,7 +514,7 @@ static int parse_vendor_opt(const char *opt) vendor = rad_dict_find_vendor_name(opt); if (vendor) return vendor->id; - + return atoi(opt); } #endif @@ -568,7 +568,7 @@ static void ippool_init2(void) char *pool_name = NULL; char *allocator = NULL; void (*generate)(struct ippool_t *pool); - + if (!s) return; @@ -581,7 +581,7 @@ static void ippool_init2(void) conf_vendor = parse_vendor_opt(opt->val); continue; } - + if (!strcmp(opt->name, "attr")) { conf_attr = parse_attr_opt(opt->val); continue; @@ -625,7 +625,7 @@ static void ippool_init2(void) _free(allocator); } } - + if (def_pool->generate) def_pool->generate(def_pool); diff --git a/accel-pppd/extra/ipv6pool.c b/accel-pppd/extra/ipv6pool.c index 0ca270c0..6887ea32 100644 --- a/accel-pppd/extra/ipv6pool.c +++ b/accel-pppd/extra/ipv6pool.c @@ -79,7 +79,7 @@ static void generate_ippool(struct in6_addr *addr, int mask, int prefix_len) *(uint64_t *)(step.s6_addr + 8) = htobe64(1llu << (128 - prefix_len)); else *(uint64_t *)step.s6_addr = htobe64(1llu << (64 - prefix_len)); - + while (in6_addr_cmp(&ip, &end) <= 0) { it = malloc(sizeof(*it)); it->it.owner = &ipdb; @@ -115,7 +115,7 @@ static void generate_dppool(struct in6_addr *addr, int mask, int prefix_len) *(uint64_t *)(step.s6_addr + 8) = htobe64(1llu << (128 - prefix_len)); else *(uint64_t *)step.s6_addr = htobe64(1llu << (64 - prefix_len)); - + while (in6_addr_cmp(&ip, &end) <= 0) { it = malloc(sizeof(*it)); it->it.owner = &ipdb; @@ -138,34 +138,34 @@ static void add_prefix(int type, const char *_val) struct in6_addr addr; int prefix_len; int mask; - + ptr1 = strchr(val, '/'); if (!ptr1) goto err; - + *ptr1 = 0; ptr2 = strchr(ptr1 + 1, ','); if (!ptr2) goto err; - + *ptr2 = 0; if (inet_pton(AF_INET6, val, &addr) == 0) goto err; - + if (sscanf(ptr1 + 1, "%i", &mask) != 1) goto err; - + if (mask < 7 || mask > 127) goto err; - + if (sscanf(ptr2 + 1, "%i", &prefix_len) != 1) goto err; - + if (prefix_len > 128 || prefix_len < mask) goto err; - + if (type) generate_dppool(&addr, mask, prefix_len); else @@ -173,7 +173,7 @@ static void add_prefix(int type, const char *_val) _free(val); return; - + err: log_error("ipv6_pool: failed to parse '%s'\n", _val); _free(val); @@ -245,7 +245,7 @@ static void ippool_init(void) if (!s) return; - + list_for_each_entry(opt, &s->items, entry) { if (!strcmp(opt->name, "delegate")) add_prefix(1, opt->val); diff --git a/accel-pppd/extra/net-snmp/agent.c b/accel-pppd/extra/net-snmp/agent.c index 9f8b1a74..162cdbc0 100644 --- a/accel-pppd/extra/net-snmp/agent.c +++ b/accel-pppd/extra/net-snmp/agent.c @@ -45,7 +45,7 @@ static int snmp_term = 0; static int agent_log(int major, int minor, void *serv_arg, void *cl_arg) { struct snmp_log_message *m = serv_arg; - + switch (m->priority) { case LOG_EMERG: log_emerg("net-snmp: %s", m->msg); @@ -96,7 +96,7 @@ static void *snmp_thread(void *a) snmp_enable_calllog(); //snmp_set_do_debugging(1); //netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1); - + if (!conf_master) netsnmp_enable_subagent(); @@ -117,11 +117,11 @@ static void *snmp_thread(void *a) if (conf_master) init_master_agent(); - + while (!snmp_term) { agent_check_and_process(1); } - + snmp_shutdown(conf_agent_name); SOCK_CLEANUP; @@ -152,11 +152,11 @@ static void init(void) opt = conf_get_opt("snmp", "agent-name"); if (opt) conf_agent_name = opt; - + /*opt = conf_get_opt("snmp", "oid-prefix") if (opt) conf_oid_prefix = opt;*/ - + pthread_create(&snmp_thr, NULL, snmp_thread, NULL); triton_context_register(&ctx, NULL); triton_context_wakeup(&ctx); diff --git a/accel-pppd/extra/net-snmp/exec_cli.c b/accel-pppd/extra/net-snmp/exec_cli.c index 63a89587..28e53383 100644 --- a/accel-pppd/extra/net-snmp/exec_cli.c +++ b/accel-pppd/extra/net-snmp/exec_cli.c @@ -36,7 +36,7 @@ static void set_action(const char *cmd, size_t len) memcpy(cc.cmdline, cmd, len); cc.cmdline[len] = 0; - + cli_process_cmd(&cc); _free(cc.cmdline); @@ -69,7 +69,7 @@ handle_cli(netsnmp_mib_handler *handler, /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - + switch(reqinfo->mode) { case MODE_GET: diff --git a/accel-pppd/extra/net-snmp/sessionTable.c b/accel-pppd/extra/net-snmp/sessionTable.c index dc7d62bd..954ca1e3 100644 --- a/accel-pppd/extra/net-snmp/sessionTable.c +++ b/accel-pppd/extra/net-snmp/sessionTable.c @@ -1,6 +1,6 @@ /* * Note: this file originally auto-generated by mib2c using - * version : 14170 $ of $ + * version : 14170 $ of $ * * $Id:$ */ @@ -42,7 +42,7 @@ init_sessionTable(void) /* * TODO:300:o: Perform sessionTable one-time module initialization. */ - + /* * here we initialize all the tables we're planning on supporting */ @@ -63,7 +63,7 @@ shutdown_sessionTable(void) } /** - * Initialize the table sessionTable + * Initialize the table sessionTable * (Define its contents and how it's structured) */ void @@ -88,13 +88,13 @@ initialize_table_sessionTable(void) * string token is used to add, find or remove pointers. */ user_context = netsnmp_create_data_list("sessionTable", NULL, NULL); - + /* * No support for any flags yet, but in the future you would * set any flags here. */ flags = 0; - + /* * call interface initialization code */ @@ -102,7 +102,7 @@ initialize_table_sessionTable(void) } /* initialize_table_sessionTable */ /** - * Shutdown the table sessionTable + * Shutdown the table sessionTable */ void shutdown_table_sessionTable(void) @@ -129,7 +129,7 @@ sessionTable_rowreq_ctx_init(sessionTable_rowreq_ctx *rowreq_ctx, DEBUGMSGTL(("verbose:sessionTable:sessionTable_rowreq_ctx_init","called\n")); netsnmp_assert(NULL != rowreq_ctx); - + /* * TODO:210:o: |-> Perform extra sessionTable rowreq initialization. (eg DEFVALS) */ @@ -146,7 +146,7 @@ void sessionTable_rowreq_ctx_cleanup(sessionTable_rowreq_ctx *rowreq_ctx) DEBUGMSGTL(("verbose:sessionTable:sessionTable_rowreq_ctx_cleanup","called\n")); netsnmp_assert(NULL != rowreq_ctx); - + /* * TODO:211:o: |-> Perform extra sessionTable rowreq cleanup. */ diff --git a/accel-pppd/extra/net-snmp/sessionTable.h b/accel-pppd/extra/net-snmp/sessionTable.h index 645ddd35..2635f21c 100644 --- a/accel-pppd/extra/net-snmp/sessionTable.h +++ b/accel-pppd/extra/net-snmp/sessionTable.h @@ -124,9 +124,9 @@ typedef struct sessionTable_rowreq_ctx_s { /** this must be first for container compare to work */ netsnmp_index oid_idx; oid oid_tmp[MAX_sessionTable_IDX_LEN]; - + sessionTable_mib_index tbl_idx; - + sessionTable_data * data; /* @@ -138,7 +138,7 @@ typedef struct sessionTable_rowreq_ctx_s { /* * TODO:131:o: | |-> Add useful data to sessionTable rowreq context. */ - + /* * storage for future expansion */ diff --git a/accel-pppd/extra/net-snmp/sessionTable_data_access.c b/accel-pppd/extra/net-snmp/sessionTable_data_access.c index ac7e94af..edc5e6b2 100644 --- a/accel-pppd/extra/net-snmp/sessionTable_data_access.c +++ b/accel-pppd/extra/net-snmp/sessionTable_data_access.c @@ -1,6 +1,6 @@ /* * Note: this file originally auto-generated by mib2c using - * version : 14170 $ of $ + * version : 14170 $ of $ * * $Id:$ */ @@ -24,7 +24,7 @@ * * These routines are used to locate the data used to satisfy * requests. - * + * * @{ */ /********************************************************************** @@ -107,7 +107,7 @@ sessionTable_container_init(netsnmp_container **container_ptr_ptr, netsnmp_cache *cache) { DEBUGMSGTL(("verbose:sessionTable:sessionTable_container_init","called\n")); - + if (NULL == container_ptr_ptr) { snmp_log(LOG_ERR,"bad container param to sessionTable_container_init\n"); return; @@ -155,7 +155,7 @@ void sessionTable_container_shutdown(netsnmp_container *container_ptr) { DEBUGMSGTL(("verbose:sessionTable:sessionTable_container_shutdown","called\n")); - + if (NULL == container_ptr) { snmp_log(LOG_ERR,"bad params to sessionTable_container_shutdown\n"); return; @@ -218,7 +218,7 @@ sessionTable_container_load(netsnmp_container *container) sessionTable_release_rowreq_ctx(rowreq_ctx); continue; } - + strcpy(rowreq_ctx->data->ifname, ses->ifname); if (ses->username) diff --git a/accel-pppd/extra/net-snmp/sessionTable_data_get.c b/accel-pppd/extra/net-snmp/sessionTable_data_get.c index d467ad05..e2b1cbc6 100644 --- a/accel-pppd/extra/net-snmp/sessionTable_data_get.c +++ b/accel-pppd/extra/net-snmp/sessionTable_data_get.c @@ -1,6 +1,6 @@ /* * Note: this file originally auto-generated by mib2c using - * version : 12088 $ of $ + * version : 12088 $ of $ * * $Id:$ */ @@ -121,7 +121,7 @@ sessionTable_indexes_set_tbl_idx(sessionTable_mib_index *tbl_idx, char *sesSID_v } tbl_idx->sesSID_len = sesSID_val_ptr_len; memcpy( tbl_idx->sesSID, sesSID_val_ptr, sesSID_val_ptr_len* sizeof(sesSID_val_ptr[0]) ); - + return MFD_SUCCESS; } /* sessionTable_indexes_set_tbl_idx */ @@ -314,7 +314,7 @@ sesUsername_get( sessionTable_rowreq_ctx *rowreq_ctx, char **sesUsername_val_ptr } (* sesUsername_val_ptr_len_ptr ) = len; memcpy( (* sesUsername_val_ptr_ptr ), rowreq_ctx->data->username, len); - + return MFD_SUCCESS; } /* sesUsername_get */ @@ -484,7 +484,7 @@ sesState_get( sessionTable_rowreq_ctx *rowreq_ctx, u_long * sesState_val_ptr ) DEBUGMSGTL(("verbose:sessionTable:sesState_get","called\n")); netsnmp_assert(NULL != rowreq_ctx); - + (* sesState_val_ptr ) = rowreq_ctx->data->state; return MFD_SUCCESS; diff --git a/accel-pppd/extra/net-snmp/sessionTable_data_set.c b/accel-pppd/extra/net-snmp/sessionTable_data_set.c index ebfeeeaa..2f3bfa02 100644 --- a/accel-pppd/extra/net-snmp/sessionTable_data_set.c +++ b/accel-pppd/extra/net-snmp/sessionTable_data_set.c @@ -18,7 +18,7 @@ * * These routines are used to set the value for individual objects. The * row context is passed, along with the new value. - * + * * @{ */ /** @} */ diff --git a/accel-pppd/extra/net-snmp/sessionTable_data_set.h b/accel-pppd/extra/net-snmp/sessionTable_data_set.h index 70534baa..c77b466c 100644 --- a/accel-pppd/extra/net-snmp/sessionTable_data_set.h +++ b/accel-pppd/extra/net-snmp/sessionTable_data_set.h @@ -1,6 +1,6 @@ /* * Note: this file originally auto-generated by mib2c using - * version : 12077 $ of $ + * version : 12077 $ of $ * * $Id:$ */ diff --git a/accel-pppd/extra/net-snmp/sessionTable_enums.h b/accel-pppd/extra/net-snmp/sessionTable_enums.h index c7ce8450..7897ff02 100644 --- a/accel-pppd/extra/net-snmp/sessionTable_enums.h +++ b/accel-pppd/extra/net-snmp/sessionTable_enums.h @@ -41,20 +41,20 @@ extern "C" { #ifndef IANATUNNELTYPE_ENUMS #define IANATUNNELTYPE_ENUMS -#define IANATUNNELTYPE_OTHER 1 -#define IANATUNNELTYPE_DIRECT 2 -#define IANATUNNELTYPE_GRE 3 -#define IANATUNNELTYPE_MINIMAL 4 -#define IANATUNNELTYPE_L2TP 5 -#define IANATUNNELTYPE_PPTP 6 -#define IANATUNNELTYPE_L2F 7 -#define IANATUNNELTYPE_UDP 8 -#define IANATUNNELTYPE_ATMP 9 -#define IANATUNNELTYPE_MSDP 10 -#define IANATUNNELTYPE_SIXTOFOUR 11 -#define IANATUNNELTYPE_SIXOVERFOUR 12 -#define IANATUNNELTYPE_ISATAP 13 -#define IANATUNNELTYPE_TEREDO 14 +#define IANATUNNELTYPE_OTHER 1 +#define IANATUNNELTYPE_DIRECT 2 +#define IANATUNNELTYPE_GRE 3 +#define IANATUNNELTYPE_MINIMAL 4 +#define IANATUNNELTYPE_L2TP 5 +#define IANATUNNELTYPE_PPTP 6 +#define IANATUNNELTYPE_L2F 7 +#define IANATUNNELTYPE_UDP 8 +#define IANATUNNELTYPE_ATMP 9 +#define IANATUNNELTYPE_MSDP 10 +#define IANATUNNELTYPE_SIXTOFOUR 11 +#define IANATUNNELTYPE_SIXOVERFOUR 12 +#define IANATUNNELTYPE_ISATAP 13 +#define IANATUNNELTYPE_TEREDO 14 #endif /* IANATUNNELTYPE_ENUMS */ @@ -69,9 +69,9 @@ extern "C" { #ifndef SESSTATE_ENUMS #define SESSTATE_ENUMS -#define SESSTATE_STARTING 1 -#define SESSTATE_ACTIVE 2 -#define SESSTATE_FINISHING 3 +#define SESSTATE_STARTING 1 +#define SESSTATE_ACTIVE 2 +#define SESSTATE_FINISHING 3 #endif /* SESSTATE_ENUMS */ diff --git a/accel-pppd/extra/net-snmp/sessionTable_interface.c b/accel-pppd/extra/net-snmp/sessionTable_interface.c index cf60f910..420336da 100644 --- a/accel-pppd/extra/net-snmp/sessionTable_interface.c +++ b/accel-pppd/extra/net-snmp/sessionTable_interface.c @@ -1,6 +1,6 @@ /* * Note: this file originally auto-generated by mib2c using - * version : 15899 $ of $ + * version : 15899 $ of $ * * $Id:$ */ @@ -60,7 +60,7 @@ typedef struct sessionTable_interface_ctx_s { netsnmp_cache *cache; sessionTable_registration * user_ctx; - + netsnmp_table_registration_info tbl_info; netsnmp_baby_steps_access_methods access_multiplexer; @@ -110,7 +110,7 @@ static Netsnmp_Node_Handler _mfd_sessionTable_object_lookup; static Netsnmp_Node_Handler _mfd_sessionTable_get_values; /** * @internal - * Initialize the table sessionTable + * Initialize the table sessionTable * (Define its contents and how it's structured) */ void @@ -160,7 +160,7 @@ _sessionTable_initialize_interface(sessionTable_registration * reg_ptr, u_long snmp_log(LOG_ERR,"could not initialize container for sessionTable\n"); return; } - + /* * access_multiplexer: REQUIRED wrapper for get request handling */ @@ -179,7 +179,7 @@ _sessionTable_initialize_interface(sessionTable_registration * reg_ptr, u_long * Create a registration, save our reg data, register table. */ DEBUGMSGTL(("sessionTable:init_sessionTable", - "Registering sessionTable as a mibs-for-dummies table.\n")); + "Registering sessionTable as a mibs-for-dummies table.\n")); handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); reginfo = netsnmp_handler_registration_create("sessionTable", handler, sessionTable_oid, @@ -210,14 +210,14 @@ _sessionTable_initialize_interface(sessionTable_registration * reg_ptr, u_long mfd_modes |= BABY_STEP_PRE_REQUEST; if( access_multiplexer->post_request ) mfd_modes |= BABY_STEP_POST_REQUEST; - + if( access_multiplexer->undo_setup ) mfd_modes |= BABY_STEP_UNDO_SETUP; if( access_multiplexer->undo_cleanup ) mfd_modes |= BABY_STEP_UNDO_CLEANUP; if( access_multiplexer->undo_sets ) mfd_modes |= BABY_STEP_UNDO_SETS; - + if( access_multiplexer->row_creation ) mfd_modes |= BABY_STEP_ROW_CREATE; if( access_multiplexer->consistency_checks ) @@ -226,7 +226,7 @@ _sessionTable_initialize_interface(sessionTable_registration * reg_ptr, u_long mfd_modes |= BABY_STEP_COMMIT; if( access_multiplexer->undo_commit ) mfd_modes |= BABY_STEP_UNDO_COMMIT; - + handler = netsnmp_baby_steps_handler_get(mfd_modes); netsnmp_inject_handler(reginfo, handler); @@ -291,7 +291,7 @@ sessionTable_index_to_oid(netsnmp_index *oid_idx, sessionTable_mib_index *mib_idx) { int err = SNMP_ERR_NOERROR; - + /* * temp storage for parsing indexes */ @@ -343,7 +343,7 @@ sessionTable_index_from_oid(netsnmp_index *oid_idx, sessionTable_mib_index *mib_idx) { int err = SNMP_ERR_NOERROR; - + /* * temp storage for parsing indexes */ @@ -460,7 +460,7 @@ sessionTable_release_rowreq_ctx(sessionTable_rowreq_ctx *rowreq_ctx) DEBUGMSGTL(("internal:sessionTable:sessionTable_release_rowreq_ctx","called\n")); netsnmp_assert(NULL != rowreq_ctx); - + sessionTable_rowreq_ctx_cleanup(rowreq_ctx); /* @@ -469,7 +469,7 @@ sessionTable_release_rowreq_ctx(sessionTable_rowreq_ctx *rowreq_ctx) if ((rowreq_ctx->data) && !(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) sessionTable_release_data(rowreq_ctx->data); - + /* * free index oid pointer */ @@ -493,13 +493,13 @@ _mfd_sessionTable_pre_request(netsnmp_mib_handler *handler, DEBUGMSGTL(("internal:sessionTable:_mfd_sessionTable_pre_request", "called\n")); - + if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) { DEBUGMSGTL(("internal:sessionTable", "skipping additional pre_request\n")); return SNMP_ERR_NOERROR; } - + rc = sessionTable_pre_request(sessionTable_if_ctx.user_ctx); if (MFD_SUCCESS != rc) { /* @@ -509,7 +509,7 @@ _mfd_sessionTable_pre_request(netsnmp_mib_handler *handler, "sessionTable_pre_request\n", rc)); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); } - + return SNMP_ERR_NOERROR; } /* _mfd_sessionTable_pre_request */ @@ -544,7 +544,7 @@ _mfd_sessionTable_post_request(netsnmp_mib_handler *handler, "waiting for last post_request\n")); return SNMP_ERR_NOERROR; } - + packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0); rc = sessionTable_post_request(sessionTable_if_ctx.user_ctx,packet_rc); if (MFD_SUCCESS != rc) { @@ -554,7 +554,7 @@ _mfd_sessionTable_post_request(netsnmp_mib_handler *handler, DEBUGMSGTL(("sessionTable","error %d from " "sessionTable_post_request\n", rc)); } - + return SNMP_ERR_NOERROR; } /* _mfd_sessionTable_post_request */ @@ -571,7 +571,7 @@ _mfd_sessionTable_object_lookup(netsnmp_mib_handler *handler, int rc = SNMP_ERR_NOERROR; sessionTable_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); - + DEBUGMSGTL(("internal:sessionTable:_mfd_sessionTable_object_lookup","called\n")); /* @@ -606,7 +606,7 @@ _sessionTable_get_column( sessionTable_rowreq_ctx *rowreq_ctx, netsnmp_variable_list *var, int column ) { int rc = SNMPERR_SUCCESS; - + DEBUGMSGTL(("internal:sessionTable:_mfd_sessionTable_get_column", "called for %d\n", column)); @@ -712,7 +712,7 @@ _mfd_sessionTable_get_values(netsnmp_mib_handler *handler, DEBUGMSGTL(("internal:sessionTable:_mfd_sessionTable_get_values","called\n")); netsnmp_assert(NULL != rowreq_ctx); - + for(;requests; requests = requests->next) { /* * save old pointer, so we can free it if replaced @@ -734,7 +734,7 @@ _mfd_sessionTable_get_values(netsnmp_mib_handler *handler, tri = netsnmp_extract_table_info(requests); if(NULL == tri) continue; - + rc = _sessionTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); if(rc) { if(MFD_SKIP == rc) { @@ -798,7 +798,7 @@ _cache_load(netsnmp_cache *cache, void *vmagic) /** should only be called for an invalid or expired cache */ netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); - + /* * call user code */ @@ -856,7 +856,7 @@ _container_free(netsnmp_container *container) * call user code */ sessionTable_container_free(container); - + /* * free all items. inefficient, but easy. */ diff --git a/accel-pppd/extra/net-snmp/sessionTable_interface.h b/accel-pppd/extra/net-snmp/sessionTable_interface.h index ebd1143d..2b99dde6 100644 --- a/accel-pppd/extra/net-snmp/sessionTable_interface.h +++ b/accel-pppd/extra/net-snmp/sessionTable_interface.h @@ -9,7 +9,7 @@ * \warning This code should not be modified, called directly, * or used to interpret functionality. It is subject to * change at any time. - * + * * @{ */ /* diff --git a/accel-pppd/extra/net-snmp/sessionTable_oids.h b/accel-pppd/extra/net-snmp/sessionTable_oids.h index 42ec6e53..0fc5c284 100644 --- a/accel-pppd/extra/net-snmp/sessionTable_oids.h +++ b/accel-pppd/extra/net-snmp/sessionTable_oids.h @@ -16,27 +16,27 @@ extern "C" { #define SESSIONTABLE_OID 1,3,6,1,4,1,8072,100,2,1 #define COLUMN_SESSID 1 - + #define COLUMN_SESIFNAME 2 - + #define COLUMN_SESUSERNAME 3 - + #define COLUMN_SESIP 4 - + #define COLUMN_SESTYPE 5 - + #define COLUMN_SESSTATE 6 - + #define COLUMN_SESUPTIME 7 - + #define COLUMN_SESCALLINGSID 8 - + #define COLUMN_SESCALLEDSID 9 - + #define SESSIONTABLE_MIN_COL COLUMN_SESSID #define SESSIONTABLE_MAX_COL COLUMN_SESCALLEDSID - + #ifdef __cplusplus diff --git a/accel-pppd/extra/net-snmp/shutdown.c b/accel-pppd/extra/net-snmp/shutdown.c index 82f85407..06c87c51 100644 --- a/accel-pppd/extra/net-snmp/shutdown.c +++ b/accel-pppd/extra/net-snmp/shutdown.c @@ -35,7 +35,7 @@ handle_shutdown(netsnmp_mib_handler *handler, /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - + switch(reqinfo->mode) { case MODE_GET: diff --git a/accel-pppd/extra/net-snmp/statCore.c b/accel-pppd/extra/net-snmp/statCore.c index 74a6b35b..55109f6a 100644 --- a/accel-pppd/extra/net-snmp/statCore.c +++ b/accel-pppd/extra/net-snmp/statCore.c @@ -55,7 +55,7 @@ handle_statCoreUpTime(netsnmp_mib_handler *handler, /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - + switch(reqinfo->mode) { case MODE_GET: @@ -84,7 +84,7 @@ handle_statCoreCPU(netsnmp_mib_handler *handler, /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - + switch(reqinfo->mode) { case MODE_GET: @@ -119,7 +119,7 @@ handle_statCoreMemRss(netsnmp_mib_handler *handler, fscanf(f, "%lu %lu", &vmsize, &vmrss); fclose(f); } - + vmrss *= page_size; /* We are never called for a GETNEXT if it's registered as a @@ -127,7 +127,7 @@ handle_statCoreMemRss(netsnmp_mib_handler *handler, /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - + switch(reqinfo->mode) { case MODE_GET: diff --git a/accel-pppd/extra/net-snmp/statIPOE.c b/accel-pppd/extra/net-snmp/statIPOE.c index be41085e..24f154fd 100644 --- a/accel-pppd/extra/net-snmp/statIPOE.c +++ b/accel-pppd/extra/net-snmp/statIPOE.c @@ -22,8 +22,8 @@ static unsigned int *stat_starting; static unsigned int *stat_active; /* - * Our initialization routine, called automatically by the agent - * (Note that the function name must match init_FILENAME()) + * Our initialization routine, called automatically by the agent + * (Note that the function name must match init_FILENAME()) */ void init_statIPOE(void) @@ -36,7 +36,7 @@ init_statIPOE(void) /* * a debugging statement. Run the agent with -DstatIPOE to see - * the output of this debugging statement. + * the output of this debugging statement. */ DEBUGMSGTL(("statIPOE", "Initializing the statIPOE module\n")); diff --git a/accel-pppd/extra/net-snmp/statL2TP.c b/accel-pppd/extra/net-snmp/statL2TP.c index a91d336a..59998386 100644 --- a/accel-pppd/extra/net-snmp/statL2TP.c +++ b/accel-pppd/extra/net-snmp/statL2TP.c @@ -23,8 +23,8 @@ static unsigned int *stat_starting; static unsigned int *stat_active; /* - * Our initialization routine, called automatically by the agent - * (Note that the function name must match init_FILENAME()) + * Our initialization routine, called automatically by the agent + * (Note that the function name must match init_FILENAME()) */ void init_statL2TP(void) @@ -37,7 +37,7 @@ init_statL2TP(void) /* * a debugging statement. Run the agent with -DstatL2TP to see - * the output of this debugging statement. + * the output of this debugging statement. */ DEBUGMSGTL(("statL2TP", "Initializing the statL2TP module\n")); diff --git a/accel-pppd/extra/net-snmp/statPPP.c b/accel-pppd/extra/net-snmp/statPPP.c index db8918b7..37e4630c 100644 --- a/accel-pppd/extra/net-snmp/statPPP.c +++ b/accel-pppd/extra/net-snmp/statPPP.c @@ -11,8 +11,8 @@ #include "ppp.h" /* - * Our initialization routine, called automatically by the agent - * (Note that the function name must match init_FILENAME()) + * Our initialization routine, called automatically by the agent + * (Note that the function name must match init_FILENAME()) */ void init_statPPP(void) @@ -26,7 +26,7 @@ init_statPPP(void) /* * a debugging statement. Run the agent with -DstatPPP to see - * the output of this debugging statement. + * the output of this debugging statement. */ DEBUGMSGTL(("statPPP", "Initializing the statPPP module\n")); diff --git a/accel-pppd/extra/net-snmp/statPPPOE.c b/accel-pppd/extra/net-snmp/statPPPOE.c index 0ca2dd86..6042dc5b 100644 --- a/accel-pppd/extra/net-snmp/statPPPOE.c +++ b/accel-pppd/extra/net-snmp/statPPPOE.c @@ -22,8 +22,8 @@ static unsigned int *stat_starting; static unsigned int *stat_active; /* - * Our initialization routine, called automatically by the agent - * (Note that the function name must match init_FILENAME()) + * Our initialization routine, called automatically by the agent + * (Note that the function name must match init_FILENAME()) */ void init_statPPPOE(void) @@ -36,7 +36,7 @@ init_statPPPOE(void) /* * a debugging statement. Run the agent with -DstatPPPOE to see - * the output of this debugging statement. + * the output of this debugging statement. */ DEBUGMSGTL(("statPPPOE", "Initializing the statPPPOE module\n")); diff --git a/accel-pppd/extra/net-snmp/statPPTP.c b/accel-pppd/extra/net-snmp/statPPTP.c index 1a13ad06..48642202 100644 --- a/accel-pppd/extra/net-snmp/statPPTP.c +++ b/accel-pppd/extra/net-snmp/statPPTP.c @@ -22,8 +22,8 @@ static unsigned int *stat_starting; static unsigned int *stat_active; /* - * Our initialization routine, called automatically by the agent - * (Note that the function name must match init_FILENAME()) + * Our initialization routine, called automatically by the agent + * (Note that the function name must match init_FILENAME()) */ void init_statPPTP(void) @@ -36,7 +36,7 @@ init_statPPTP(void) /* * a debugging statement. Run the agent with -DstatPPTP to see - * the output of this debugging statement. + * the output of this debugging statement. */ DEBUGMSGTL(("statPPTP", "Initializing the statPPTP module\n")); diff --git a/accel-pppd/extra/net-snmp/terminate.c b/accel-pppd/extra/net-snmp/terminate.c index 23d355a2..e7e5d12c 100644 --- a/accel-pppd/extra/net-snmp/terminate.c +++ b/accel-pppd/extra/net-snmp/terminate.c @@ -63,7 +63,7 @@ static void terminate_by_ip(const char *val, size_t len) str[len] = 0; addr = inet_addr(str); - + pthread_rwlock_rdlock(&ses_lock); list_for_each_entry(ses, &ses_list, entry) { if (!ses->ipv4 || ses->ipv4->peer_addr != addr) @@ -139,7 +139,7 @@ handle_termBySID(netsnmp_mib_handler *handler, /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - + switch(reqinfo->mode) { case MODE_GET: @@ -200,7 +200,7 @@ handle_termByIfName(netsnmp_mib_handler *handler, /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - + switch(reqinfo->mode) { case MODE_GET: @@ -262,7 +262,7 @@ handle_termByIP(netsnmp_mib_handler *handler, /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - + switch(reqinfo->mode) { case MODE_GET: @@ -326,7 +326,7 @@ handle_termByUsername(netsnmp_mib_handler *handler, /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - + switch(reqinfo->mode) { case MODE_GET: diff --git a/accel-pppd/extra/pppd_compat.c b/accel-pppd/extra/pppd_compat.c index e48029bb..482a7080 100644 --- a/accel-pppd/extra/pppd_compat.c +++ b/accel-pppd/extra/pppd_compat.c @@ -113,7 +113,7 @@ static void ip_change_handler(struct sigchld_handler_t *h, int status) static void ev_ses_starting(struct ap_session *ses) { struct pppd_compat_pd *pd; - + pd = _malloc(sizeof(*pd)); if (!pd) { log_emerg("pppd_compat: out of memory\n"); @@ -139,7 +139,7 @@ static void ev_ses_pre_up(struct ap_session *ses) char ipaddr[17]; char peer_ipaddr[17]; struct pppd_compat_pd *pd = find_pd(ses); - + if (!pd) return; @@ -169,7 +169,7 @@ static void ev_ses_pre_up(struct ap_session *ses) argv[4] = ipaddr; argv[5] = peer_ipaddr; fill_argv(argv, pd, conf_ip_up); - + fill_env(env, env_mem, pd); if (conf_ip_pre_up) { @@ -210,14 +210,14 @@ static void ev_ses_started(struct ap_session *ses) char ipaddr[17]; char peer_ipaddr[17]; struct pppd_compat_pd *pd = find_pd(ses); - + if (!pd) return; - + argv[4] = ipaddr; argv[5] = peer_ipaddr; fill_argv(argv, pd, conf_ip_up); - + fill_env(env, env_mem, pd); if (conf_ip_up) { @@ -240,7 +240,7 @@ static void ev_ses_started(struct ap_session *ses) } else log_error("pppd_compat: fork: %s\n", strerror(errno)); } - + pd->started = 1; } @@ -253,10 +253,10 @@ static void ev_ses_finished(struct ap_session *ses) char ipaddr[17]; char peer_ipaddr[17]; struct pppd_compat_pd *pd = find_pd(ses); - + if (!pd) return; - + if (!pd->started) goto skip; @@ -312,7 +312,7 @@ skip: if (pd->radattr_saved) remove_radattr(pd); #endif - + list_del(&pd->pd.entry); _free(pd); } @@ -339,7 +339,7 @@ static void ev_radius_coa(struct ev_radius_t *ev) char ipaddr[17]; char peer_ipaddr[17]; struct pppd_compat_pd *pd = find_pd(ev->ses); - + if (!pd) return; @@ -373,7 +373,7 @@ static void ev_radius_coa(struct ev_radius_t *ev) static void remove_radattr(struct pppd_compat_pd *pd) { char *fname; - + if (pd->tmp_fname) { unlink(pd->tmp_fname); _free(pd->tmp_fname); @@ -464,7 +464,7 @@ static void write_radattr(struct pppd_compat_pd *pd, struct rad_packet_t *pack) fclose(f); } else log_ppp_warn("pppd_compat: failed to create '%s': %s\n", fname1, strerror(errno)); - + if (ses->state == AP_STATE_ACTIVE) { _free(fname1); _free(fname2); @@ -484,7 +484,7 @@ static struct pppd_compat_pd *find_pd(struct ap_session *ses) return cpd; } } - + //log_ppp_warn("pppd_compat: pd not found\n"); return NULL; } @@ -516,10 +516,10 @@ static void fill_env(char **env, char *mem, struct pppd_compat_pd *pd) struct ap_session *ses = pd->ses; uint64_t tx_bytes, rx_bytes; int n = 0; - + tx_bytes = (uint64_t)ses->acct_tx_bytes + 4294967296llu*ses->acct_output_gigawords; rx_bytes = (uint64_t)ses->acct_rx_bytes + 4294967296llu*ses->acct_input_gigawords; - + env[n++] = mem; mem += sprintf(mem, "PEERNAME=%s", pd->ses->username) + 1; env[n++] = mem; @@ -546,7 +546,7 @@ static void fill_env(char **env, char *mem, struct pppd_compat_pd *pd) inet_ntop(AF_INET6, &a->addr, mem, ENV_MEM); mem = strchr(mem, 0); mem += sprintf(mem, "/%i", a->prefix_len) + 1; } - + if (pd->ses->stop_time) { env[n++] = mem; mem += sprintf(mem, "CONNECT_TIME=%lu", pd->ses->stop_time - pd->ses->start_time) + 1; diff --git a/accel-pppd/extra/sigchld.c b/accel-pppd/extra/sigchld.c index d6b0df5f..cfce2cd2 100644 --- a/accel-pppd/extra/sigchld.c +++ b/accel-pppd/extra/sigchld.c @@ -34,7 +34,7 @@ static void* sigchld_thread(void *arg) sigaddset(&set, SIGCHLD); sigaddset(&set, SIGQUIT); - while (1) { + while (1) { pid = waitpid(-1, &status, 0); if (pid < 0) { if (errno == EINTR) diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h index b2ee1b6b..12f2937e 100644 --- a/accel-pppd/include/ap_session.h +++ b/accel-pppd/include/ap_session.h @@ -95,7 +95,7 @@ struct ap_session int terminate_cause; struct list_head pd_list; - + uint32_t acct_rx_bytes; uint32_t acct_tx_bytes; uint32_t acct_input_gigawords; diff --git a/accel-pppd/include/ppp_auth.h b/accel-pppd/include/ppp_auth.h index 9c684668..839a8817 100644 --- a/accel-pppd/include/ppp_auth.h +++ b/accel-pppd/include/ppp_auth.h @@ -9,7 +9,7 @@ struct auth_data_t { struct list_head entry; int proto; - int state; + int state; struct ppp_auth_handler_t *h; }; diff --git a/accel-pppd/iprange.c b/accel-pppd/iprange.c index c3bf2fec..6ea2c2f9 100644 --- a/accel-pppd/iprange.c +++ b/accel-pppd/iprange.c @@ -30,7 +30,7 @@ static struct iprange_t *parse1(const char *str) int n,f1,f2,f3,f4,m; struct iprange_t *r; int mask; - + n = sscanf(str, "%u.%u.%u.%u/%u",&f1, &f2, &f3, &f4, &m); if (n != 5) return NULL; @@ -44,14 +44,14 @@ static struct iprange_t *parse1(const char *str) return NULL; if (m > 32) return NULL; - + r = _malloc(sizeof(*r)); r->begin = (f4 << 24) | (f3 << 16) | (f2 << 8) | f1; - + mask = htonl(~((1 << (32 - m)) - 1)); r->end = ntohl(r->begin | ~mask); r->begin = ntohl(r->begin); - + return r; } @@ -74,7 +74,7 @@ static struct iprange_t *parse2(const char *str) return NULL; if (m < f4 || m > 255) return NULL; - + r = _malloc(sizeof(*r)); r->begin = ntohl((f4 << 24) | (f3 << 16) | (f2 << 8) | f1); r->end = ntohl((m << 24) | (f3 << 16) | (f2 << 8) | f1); @@ -118,7 +118,7 @@ static int check_range(struct list_head *list, in_addr_t ipaddr) { struct iprange_t *r; uint32_t a = ntohl(ipaddr); - + list_for_each_entry(r, list, entry) { if (a >= r->begin && a <= r->end) return 0; diff --git a/accel-pppd/ipv6/dhcpv6.h b/accel-pppd/ipv6/dhcpv6.h index 82e366e7..1166445c 100644 --- a/accel-pppd/ipv6/dhcpv6.h +++ b/accel-pppd/ipv6/dhcpv6.h @@ -158,7 +158,7 @@ struct dhcpv6_packet { struct ap_session *ses; struct dhcpv6_pd *pd; struct sockaddr_in6 addr; - + struct dhcpv6_msg_hdr *hdr; struct dhcpv6_opt_clientid *clientid; struct dhcpv6_opt_serverid *serverid; diff --git a/accel-pppd/ipv6/dhcpv6_packet.c b/accel-pppd/ipv6/dhcpv6_packet.c index 71184911..16db5cb9 100644 --- a/accel-pppd/ipv6/dhcpv6_packet.c +++ b/accel-pppd/ipv6/dhcpv6_packet.c @@ -69,7 +69,7 @@ static void *parse_option(void *ptr, void *endptr, struct list_head *opt_list) log_warn("dhcpv6: invalid packet received\n"); return NULL; } - + opt = _malloc(sizeof(*opt)); if (!opt) { log_emerg("out of memory\n"); @@ -85,7 +85,7 @@ static void *parse_option(void *ptr, void *endptr, struct list_head *opt_list) if (dopt->code == ntohs(opth->code)) break; } - + if (dopt->len) { endptr = ptr + sizeof(*opth) + ntohs(opth->len); ptr += dopt->len; @@ -96,7 +96,7 @@ static void *parse_option(void *ptr, void *endptr, struct list_head *opt_list) } } else ptr += sizeof(*opth) + ntohs(opth->len); - + return ptr; } @@ -148,13 +148,13 @@ struct dhcpv6_packet *dhcpv6_packet_parse(const void *buf, size_t size) struct dhcpv6_option *dhcpv6_option_alloc(struct dhcpv6_packet *pkt, int code, int len) { struct dhcpv6_option *opt; - + opt = _malloc(sizeof(*opt)); if (!opt) { log_emerg("out of memory\n"); return NULL; } - + memset(opt, 0, sizeof(*opt)); INIT_LIST_HEAD(&opt->opt_list); @@ -172,13 +172,13 @@ struct dhcpv6_option *dhcpv6_option_alloc(struct dhcpv6_packet *pkt, int code, i struct dhcpv6_option *dhcpv6_nested_option_alloc(struct dhcpv6_packet *pkt, struct dhcpv6_option *popt, int code, int len) { struct dhcpv6_option *opt; - + opt = _malloc(sizeof(*opt)); if (!opt) { log_emerg("out of memory\n"); return NULL; } - + memset(opt, 0, sizeof(*opt)); INIT_LIST_HEAD(&opt->opt_list); opt->parent = popt; @@ -204,7 +204,7 @@ struct dhcpv6_packet *dhcpv6_packet_alloc_reply(struct dhcpv6_packet *req, int t { struct dhcpv6_packet *pkt = _malloc(sizeof(*pkt)); struct dhcpv6_option *opt; - + if (!pkt) { log_emerg("out of memory\n"); return NULL; @@ -306,7 +306,7 @@ void dhcpv6_packet_print(struct dhcpv6_packet *pkt, void (*print)(const char *fm print("Unknown"); else print("%s", type_name[pkt->hdr->type - 1]); - + print(" XID=%x", pkt->hdr->trans_id); print_options(&pkt->opt_list, 0, print); @@ -320,7 +320,7 @@ static void print_clientid(struct dhcpv6_option *opt, void (*print)(const char * struct dhcpv6_opt_clientid *o = (struct dhcpv6_opt_clientid *)opt->hdr; print(" %i:", htons(o->duid.type)); - + for (i = 0; i < ntohs(o->hdr.len) - 2; i++) print("%02x", o->duid.u.raw[i]); } @@ -358,7 +358,7 @@ static void print_oro(struct dhcpv6_option *opt, void (*print)(const char *fmt, for (; ptr < end_ptr; ptr++) { if (f) print(","); - else + else print(" "); for (dopt = known_options; dopt->code; dopt++) { diff --git a/accel-pppd/libnetlink/genl.c b/accel-pppd/libnetlink/genl.c index 7d745566..68405ba1 100644 --- a/accel-pppd/libnetlink/genl.c +++ b/accel-pppd/libnetlink/genl.c @@ -83,12 +83,12 @@ int __export genl_resolve_mcg(const char *family, const char *name, int *fam_id) if (!tb[CTRL_ATTR_MCAST_GROUPS]) goto out; - + if (fam_id) *fam_id = *(uint32_t *)(RTA_DATA(tb[CTRL_ATTR_FAMILY_ID])); - + parse_rtattr_nested(tb2, GENL_MAX_FAM_GRPS, tb[CTRL_ATTR_MCAST_GROUPS]); - + for (i = 1; i < GENL_MAX_FAM_GRPS; i++) { if (tb2[i]) { parse_rtattr_nested(tb3, CTRL_ATTR_MCAST_GRP_MAX, tb2[i]); diff --git a/accel-pppd/libnetlink/ipset.c b/accel-pppd/libnetlink/ipset.c index 73125352..7834b644 100644 --- a/accel-pppd/libnetlink/ipset.c +++ b/accel-pppd/libnetlink/ipset.c @@ -41,7 +41,7 @@ static int __ipset_cmd(const char *name, in_addr_t addr, int cmd, int flags) log_error("ipset: cannot open rtnetlink\n"); return -1; } - + memset(&req, 0, sizeof(req) - 4096); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nfgenmsg)); @@ -53,18 +53,18 @@ static int __ipset_cmd(const char *name, in_addr_t addr, int cmd, int flags) addattr_l(&req.n, 4096, IPSET_ATTR_PROTOCOL, &protocol, 1); addattr_l(&req.n, 4096, IPSET_ATTR_SETNAME, name, strlen(name) + 1); - + tail1 = addattr_nest(&req.n, MAX_MSG, IPSET_ATTR_DATA | NLA_F_NESTED); tail2 = addattr_nest(&req.n, MAX_MSG, IPSET_ATTR_IP | NLA_F_NESTED); addattr32(&req.n, 4096, IPSET_ATTR_IPADDR_IPV4 | NLA_F_NET_BYTEORDER, addr); addattr_nest_end(&req.n, tail2); - + addattr_nest_end(&req.n, tail1); - + if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) goto out_err; - + rtnl_close(&rth); return 0; @@ -100,7 +100,7 @@ int __export ipset_flush(const char *name) log_error("ipset: cannot open rtnetlink\n"); return -1; } - + memset(&req, 0, sizeof(req) - 4096); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nfgenmsg)); @@ -112,10 +112,10 @@ int __export ipset_flush(const char *name) addattr_l(&req.n, 4096, IPSET_ATTR_PROTOCOL, &protocol, 1); addattr_l(&req.n, 4096, IPSET_ATTR_SETNAME, name, strlen(name) + 1); - + if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) goto out_err; - + rtnl_close(&rth); return 0; diff --git a/accel-pppd/libnetlink/libnetlink.c b/accel-pppd/libnetlink/libnetlink.c index 026df82b..0536783a 100644 --- a/accel-pppd/libnetlink/libnetlink.c +++ b/accel-pppd/libnetlink/libnetlink.c @@ -139,7 +139,7 @@ int __export rtnl_send_check(struct rtnl_handle *rth, const char *buf, int len) struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) log_debug("libnetlink: ""ERROR truncated\n"); - else + else errno = -err->error; return -1; } diff --git a/accel-pppd/log.c b/accel-pppd/log.c index dcb2b113..0d481ad9 100644 --- a/accel-pppd/log.c +++ b/accel-pppd/log.c @@ -256,7 +256,7 @@ void __export log_free_msg(struct log_msg_t *m) struct _log_msg_t *msg = (struct _log_msg_t *)m->lpd; //printf("free msg %p\n", m); - + mempool_free(m->hdr); _log_free_msg(msg); @@ -270,7 +270,7 @@ static void _log_free_msg(struct _log_msg_t *msg) if (__sync_sub_and_fetch(&msg->refs, 1)) return; - + while(!list_empty(&msg->chunks)) { chunk = list_entry(msg->chunks.next, typeof(*chunk), entry); list_del(&chunk->entry); @@ -287,13 +287,13 @@ static struct log_msg_t *clone_msg(struct _log_msg_t *msg) log_emerg("log: out of memory\n"); return NULL; } - + m->hdr = mempool_alloc(chunk_pool); if (!m->hdr) { log_emerg("log: out of memory\n"); mempool_free(m); return NULL; - } + } m->hdr->len = 0; m->lpd = msg; @@ -311,14 +311,14 @@ static int add_msg(struct _log_msg_t *msg, const char *buf) { struct log_chunk_t *chunk; int i, chunk_cnt, len = strlen(buf); - + if (!list_empty(&msg->chunks)) { chunk = list_entry(msg->chunks.prev, typeof(*chunk), entry); i = min(len, LOG_CHUNK_SIZE - chunk->len); memcpy(chunk->msg + chunk->len, buf, i); chunk->len += i; chunk->msg[chunk->len] = 0; - + if (i == len) return 0; @@ -358,10 +358,10 @@ static void write_msg(FILE *f, struct _log_msg_t *msg, struct ap_session *ses) if (ses) fprintf(f, "%s: %s: ", ses->ifname, ses->sessionid); - + list_for_each_entry(chunk, &msg->chunks, entry) fwrite(chunk->msg, chunk->len, 1, f); - + fflush(f); pthread_mutex_unlock(&lock); } @@ -444,7 +444,7 @@ static void ev_ppp_authorized(struct ap_session *ses) struct _log_msg_t *msg; struct log_msg_t *m; struct log_target_t *t; - + list_for_each_entry(t, &targets, entry) if (t->session_start) t->session_start(ppp); diff --git a/accel-pppd/log.h b/accel-pppd/log.h index 0b4c1cee..5f3fd967 100644 --- a/accel-pppd/log.h +++ b/accel-pppd/log.h @@ -19,7 +19,7 @@ struct log_msg_t struct timeval timestamp; int level; struct log_chunk_t *hdr; - struct list_head *chunks; + struct list_head *chunks; }; struct log_chunk_t diff --git a/accel-pppd/logs/log_file.c b/accel-pppd/logs/log_file.c index 518f2c99..30bfde46 100644 --- a/accel-pppd/logs/log_file.c +++ b/accel-pppd/logs/log_file.c @@ -91,15 +91,15 @@ static int log_file_open(struct log_file_t *lf, const char *fname) if (lf->fd < 0) { log_emerg("log_file: open '%s': %s\n", fname, strerror(errno)); return -1; - } - + } + return 0; } static void purge(struct list_head *list) { struct log_msg_t *msg; - + while (!list_empty(list)) { msg = list_first_entry(list, typeof(*msg), entry); list_del(&msg->entry); @@ -117,7 +117,7 @@ static void *log_thread(void *unused) LIST_HEAD(msg_list); LIST_HEAD(free_list); sigset_t set; - + sigfillset(&set); sigdelset(&set, SIGKILL); sigdelset(&set, SIGSTOP); @@ -132,7 +132,7 @@ static void *log_thread(void *unused) pthread_mutex_unlock(&lock); iov_cnt = 0; - + while (1) { if (lf->new_fd != -1) { close(lf->fd); @@ -156,13 +156,13 @@ static void *log_thread(void *unused) mempool_free(lf->lpd); } else spin_unlock(&lf->lock); - + break; } - + list_splice_init(&lf->msgs, &msg_list); spin_unlock(&lf->lock); - + while (!list_empty(&msg_list)) { msg = list_first_entry(&msg_list, typeof(*msg), entry); @@ -183,7 +183,7 @@ static void *log_thread(void *unused) purge(&free_list); } } - + list_move_tail(&msg->entry, &free_list); } } @@ -243,7 +243,7 @@ static void set_hdr(struct log_msg_t *msg, struct ap_session *ses) localtime_r(&msg->timestamp.tv_sec, &tm); strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", &tm); - sprintf(msg->hdr->msg, "%s[%s]: %s: %s%s%s", conf_color ? level_color[msg->level] : "", + sprintf(msg->hdr->msg, "%s[%s]: %s: %s%s%s", conf_color ? level_color[msg->level] : "", timestamp, level_name[msg->level], ses ? ses->ifname : "", ses ? ": " : "", @@ -319,7 +319,7 @@ static void per_user_log(struct log_target_t *t, struct log_msg_t *msg, struct a static void per_session_log(struct log_target_t *t, struct log_msg_t *msg, struct ap_session *ses) { struct log_file_pd_t *lpd; - + if (!ses) { log_free_msg(msg); return; @@ -339,7 +339,7 @@ static void per_session_log(struct log_target_t *t, struct log_msg_t *msg, struc static void fail_log(struct log_target_t *t, struct log_msg_t *msg, struct ap_session *ses) { struct fail_log_pd_t *fpd; - + if (!ses || !conf_fail_log) { log_free_msg(msg); return; @@ -365,7 +365,7 @@ static void fail_reopen(void) log_emerg("log_file: open '%s': %s\n", fname, strerror(errno)); return; } - + spin_lock(&fail_log_file->lock); if (fail_log_file->queued) fail_log_file->new_fd = fd; @@ -434,7 +434,7 @@ static void ev_ses_authorized2(struct ap_session *ses) fpd = find_fpd(ses, &pd_key3); if (!fpd) return; - + while (!list_empty(&fpd->msgs)) { msg = list_entry(fpd->msgs.next, typeof(*msg), entry); list_del(&msg->entry); @@ -453,7 +453,7 @@ static void ev_ses_authorized1(struct ap_session *ses) lpd = find_lpd(ses, &pd_key1); if (!lpd) return; - + fname = _malloc(PATH_MAX); if (!fname) { log_emerg("log_file: out of memory\n"); @@ -599,7 +599,7 @@ static void ev_ses_starting(struct ap_session *ses) lpd = find_lpd(ses, &pd_key2); if (!lpd) return; - + fname1 = _malloc(PATH_MAX); if (!fname1) { log_emerg("log_file: out of memory\n"); @@ -631,23 +631,23 @@ static void ev_ses_starting(struct ap_session *ses) _free(fname2); } -static struct log_target_t general_target = +static struct log_target_t general_target = { .log = general_log, .reopen = general_reopen, }; -static struct log_target_t per_user_target = +static struct log_target_t per_user_target = { .log = per_user_log, }; -static struct log_target_t per_session_target = +static struct log_target_t per_session_target = { .log = per_session_log, }; -static struct log_target_t fail_log_target = +static struct log_target_t fail_log_target = { .log = fail_log, .reopen = fail_reopen, @@ -659,7 +659,7 @@ static void init(void) const char *opt; pthread_create(&log_thr, NULL, log_thread, NULL); - + lpd_pool = mempool_create(sizeof(struct log_file_pd_t)); fpd_pool = mempool_create(sizeof(struct fail_log_pd_t)); @@ -673,7 +673,7 @@ static void init(void) _exit(EXIT_FAILURE); } } - + opt = conf_get_opt("log", "log-fail-file"); if (opt) { fail_log_file = malloc(sizeof(*fail_log_file)); @@ -685,11 +685,11 @@ static void init(void) } conf_fail_log = 1; } - + opt = conf_get_opt("log","color"); if (opt && atoi(opt) > 0) conf_color = 1; - + opt = conf_get_opt("log", "per-user-dir"); if (opt) conf_per_user_dir = _strdup(opt); @@ -701,23 +701,23 @@ static void init(void) opt = conf_get_opt("log", "per-session"); if (opt && atoi(opt) > 0) conf_per_session = 1; - + opt = conf_get_opt("log", "copy"); if (opt && atoi(opt) > 0) conf_copy = 1; log_register_target(&general_target); - + if (conf_per_user_dir) { log_register_target(&per_user_target); triton_event_register_handler(EV_SES_AUTHORIZED, (triton_event_func)ev_ses_authorized1); } - + if (conf_per_session_dir) { log_register_target(&per_session_target); triton_event_register_handler(EV_SES_STARTING, (triton_event_func)ev_ses_starting); } - + if (conf_fail_log) { log_register_target(&fail_log_target); triton_event_register_handler(EV_SES_AUTHORIZED, (triton_event_func)ev_ses_authorized2); diff --git a/accel-pppd/logs/log_pgsql.c b/accel-pppd/logs/log_pgsql.c index 26c16c06..e4b5a9e9 100644 --- a/accel-pppd/logs/log_pgsql.c +++ b/accel-pppd/logs/log_pgsql.c @@ -68,9 +68,9 @@ static void set_hdr(struct log_msg_t *msg, struct ap_session *ses) msg->hdr->len += strlen(ses->username) + 1; strcpy(msg->hdr->msg + msg->hdr->len, ses->sessionid); msg->hdr->len += strlen(ses->sessionid) + 1; - } else + } else memset(msg->hdr->msg + msg->hdr->len, 0, 2); - + } static void write_next_msg(void) @@ -159,7 +159,7 @@ static int pgsql_flush(struct triton_md_handler_t *h) log_emerg("log_pgsql: %s\n", PQerrorMessage(conn)); if (r == 1) return 0; - + triton_md_disable_handler(&pgsql_hnd, MD_MODE_WRITE); return 0; } @@ -272,7 +272,7 @@ static void pgsql_close(struct triton_context_t *ctx) conn = NULL; triton_context_unregister(&pgsql_ctx); } else - need_close = 1; + need_close = 1; spin_unlock(&queue_lock); } @@ -294,7 +294,7 @@ static void init(void) opt = conf_get_opt("log-pgsql", "connect-inteval"); if (opt && atoi(opt) > 0) connect_timer.period = atoi(opt) * 1000; - + opt = conf_get_opt("log-pgsql", "log-query"); if (opt) conf_query = _strdup(opt); diff --git a/accel-pppd/logs/log_syslog.c b/accel-pppd/logs/log_syslog.c index b0b079aa..36c8775b 100644 --- a/accel-pppd/logs/log_syslog.c +++ b/accel-pppd/logs/log_syslog.c @@ -55,7 +55,7 @@ static void set_hdr(struct log_msg_t *msg, struct ap_session *ses) if (ses) { if (snprintf(msg->hdr->msg, LOG_CHUNK_SIZE, "%s:%s: ", ses->ifname, ses->username ? ses->username : "")) strcpy(msg->hdr->msg + LOG_CHUNK_SIZE - 3, ": "); - } else + } else msg->hdr->msg[0] = 0; } @@ -123,7 +123,7 @@ static void syslog_close(struct triton_context_t *ctx) if (sleeping) { triton_context_unregister(&syslog_ctx); } else - need_close = 1; + need_close = 1; spin_unlock(&queue_lock); } diff --git a/accel-pppd/logs/log_tcp.c b/accel-pppd/logs/log_tcp.c index 5f592d95..616809f0 100644 --- a/accel-pppd/logs/log_tcp.c +++ b/accel-pppd/logs/log_tcp.c @@ -207,9 +207,9 @@ static void start_connect(struct tcp_target_t *t) log_emerg("log-tcp: socket: %s\n", strerror(errno)); return; } - + fcntl(t->hnd.fd, F_SETFD, fcntl(t->hnd.fd, F_GETFD) | FD_CLOEXEC); - + if (fcntl(t->hnd.fd, F_SETFL, O_NONBLOCK)) { log_emerg("log-tcp: failed to set nonblocking mode: %s\n", strerror(errno)); close(t->hnd.fd); @@ -304,7 +304,7 @@ static void init(void) { struct conf_sect_t *s = conf_get_section("log"); struct conf_option_t *opt; - + if (!s) return; diff --git a/accel-pppd/main.c b/accel-pppd/main.c index 7be67670..9eb08e10 100644 --- a/accel-pppd/main.c +++ b/accel-pppd/main.c @@ -111,7 +111,7 @@ static void close_all_fd(void) int fd; sprintf(path, "/proc/%u/fd", getpid()); - + dirp = opendir(path); if (!dirp) return; @@ -162,7 +162,7 @@ static void sigsegv(int num) int status; pthread_sigmask(SIG_SETMASK, &orig_set, NULL); - + if (conf_dump) { FILE *f; unsigned int t = time(NULL); @@ -182,8 +182,8 @@ static void sigsegv(int num) sprintf(cmd, "gdb -x %s %s %d > dump-%u", fname, exec_file, getpid(), t); system(cmd); - - unlink(fname); + + unlink(fname); } out: @@ -242,12 +242,12 @@ int main(int _argc, char **_argv) if (!conf_file) goto usage; - + if (internal) { while (getppid() != 1) sleep(1); } - + if (triton_init(conf_file)) _exit(EXIT_FAILURE); @@ -300,12 +300,12 @@ int main(int _argc, char **_argv) sa.sa_handler = config_reload; sa.sa_mask = set; sigaction(SIGUSR1, &sa, NULL); - + sa.sa_handler = sigsegv; sa.sa_mask = set; sigaction(SIGSEGV, &sa, NULL); - + sigdelset(&set, SIGKILL); sigdelset(&set, SIGSTOP); sigdelset(&set, SIGSEGV); @@ -334,7 +334,7 @@ int main(int _argc, char **_argv) sigwait(&set, &sig); log_info1("terminate, sig = %i\n", sig); - + triton_terminate(); return EXIT_SUCCESS; diff --git a/accel-pppd/memdebug.c b/accel-pppd/memdebug.c index 4b374008..08c6ad05 100644 --- a/accel-pppd/memdebug.c +++ b/accel-pppd/memdebug.c @@ -92,7 +92,7 @@ void __export md_free(void *ptr, const char *fname, int line) mem->size, mem->fname, mem->line, fname, line); abort(); } - + mem->magic1 = 0; mem->magic2 = 0; @@ -232,7 +232,7 @@ void __export md_check(void *ptr) if (!ptr) abort(); - + if (mem->magic1 != MAGIC1) abort(); diff --git a/accel-pppd/ppp/ccp_mppe.c b/accel-pppd/ppp/ccp_mppe.c index 68b95a6b..31bbad4d 100644 --- a/accel-pppd/ppp/ccp_mppe.c +++ b/accel-pppd/ppp/ccp_mppe.c @@ -75,10 +75,10 @@ static struct ccp_option_t *mppe_init(struct ppp_ccp_t *ccp) mppe_opt->mppe = 1; else mppe_opt->mppe = -1; - + if (mppe == MPPE_REQUIRE || mppe == MPPE_PREFER) ccp->ld.passive = 0; - + if (mppe == MPPE_REQUIRE) ccp->ld.optional = 0; @@ -153,7 +153,7 @@ static int __mppe_send_conf_req(struct ppp_ccp_t *ccp, struct ccp_option_t *opt, opt32->hdr.id = CI_MPPE; opt32->hdr.len = 6; opt32->val = mppe_opt->mppe ? htonl(MPPE_S | MPPE_H) : 0; - + if (setup_key && mppe_opt->mppe && setup_mppe_key(ccp->ppp->unit_fd, 0, mppe_opt->recv_key)) return 0; @@ -189,7 +189,7 @@ static int mppe_recv_conf_req(struct ppp_ccp_t *ccp, struct ccp_option_t *opt, u return CCP_OPT_NAK; return CCP_OPT_ACK; } - + if (opt32->hdr.len != 6) return CCP_OPT_REJ; @@ -209,7 +209,7 @@ static int mppe_recv_conf_req(struct ppp_ccp_t *ccp, struct ccp_option_t *opt, u mppe_opt->mppe = 0; } else return CCP_OPT_REJ; - + if (mppe_opt->mppe) { if (setup_mppe_key(ccp->ppp->unit_fd, 1, mppe_opt->send_key)) return CCP_OPT_REJ; @@ -283,7 +283,7 @@ static void mppe_print(void (*print)(const char *fmt,...),struct ccp_option_t *o bits & MPPE_S ? "+" : "-", bits & MPPE_L ? "+" : "-", bits & MPPE_D ? "+" : "-", - bits & MPPE_C ? "+" : "-" + bits & MPPE_C ? "+" : "-" ); } @@ -304,7 +304,7 @@ static void ev_mppe_keys(struct ev_mppe_keys_t *ev) mppe_opt->mppe = 0; return; } - + if (ccp->ppp->ses.ctrl->mppe == MPPE_UNSET) mppe = conf_mppe; else @@ -348,7 +348,7 @@ static void mppe_opt_init() { ccp_option_register(&mppe_opt_hnd); triton_event_register_handler(EV_MPPE_KEYS, (triton_event_func)ev_mppe_keys); - + load_config(); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); } diff --git a/accel-pppd/ppp/ipcp_opt_dns.c b/accel-pppd/ppp/ipcp_opt_dns.c index bd5114ac..f4028448 100644 --- a/accel-pppd/ppp/ipcp_opt_dns.c +++ b/accel-pppd/ppp/ipcp_opt_dns.c @@ -109,7 +109,7 @@ static int dns_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, if (dns_opt->addr == opt32->val) return IPCP_OPT_ACK; - + return IPCP_OPT_NAK; } @@ -123,7 +123,7 @@ static void dns1_print(void (*print)(const char *fmt, ...), struct ipcp_option_t in.s_addr = opt32->val; else in.s_addr = dns_opt->addr; - + print("<dns1 %s>", inet_ntoa(in)); } @@ -137,7 +137,7 @@ static void dns2_print(void (*print)(const char *fmt, ...), struct ipcp_option_t in.s_addr = opt32->val; else in.s_addr = dns_opt->addr; - + print("<dns2 %s>", inet_ntoa(in)); } @@ -148,7 +148,7 @@ static void ev_dns(struct ev_dns_t *ev) if (!ev->ses->ctrl->ppp) return; - + ppp = container_of(ev->ses, typeof(*ppp), ses); dns_opt = container_of(ipcp_find_option(ppp, &dns1_opt_hnd), typeof(*dns_opt), opt); @@ -161,11 +161,11 @@ static void ev_dns(struct ev_dns_t *ev) static void load_config(void) { char *opt; - + opt = conf_get_opt("dns", "dns1"); if (opt) conf_dns1 = inet_addr(opt); - + opt = conf_get_opt("dns", "dns2"); if (opt) conf_dns2 = inet_addr(opt); diff --git a/accel-pppd/ppp/ipcp_opt_ipaddr.c b/accel-pppd/ppp/ipcp_opt_ipaddr.c index 8a77848e..7bac55bf 100644 --- a/accel-pppd/ppp/ipcp_opt_ipaddr.c +++ b/accel-pppd/ppp/ipcp_opt_ipaddr.c @@ -86,19 +86,19 @@ static int alloc_ip(struct ppp_t *ppp) log_ppp_warn("ppp: no free IPv4 address\n"); return IPCP_OPT_CLOSE; } - + if (iprange_tunnel_check(ppp->ses.ipv4->peer_addr)) { log_ppp_warn("ppp:ipcp: to avoid kernel soft lockup requested IP cannot be assigned (%i.%i.%i.%i)\n", - ppp->ses.ipv4->peer_addr&0xff, - (ppp->ses.ipv4->peer_addr >> 8)&0xff, - (ppp->ses.ipv4->peer_addr >> 16)&0xff, + ppp->ses.ipv4->peer_addr&0xff, + (ppp->ses.ipv4->peer_addr >> 8)&0xff, + (ppp->ses.ipv4->peer_addr >> 16)&0xff, (ppp->ses.ipv4->peer_addr >> 24)&0xff); return IPCP_OPT_FAIL; } - + if (conf_check_exists && check_exists(ppp, ppp->ses.ipv4->peer_addr)) return IPCP_OPT_FAIL; - + return 0; } @@ -107,13 +107,13 @@ static int ipaddr_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o struct ipaddr_option_t *ipaddr_opt = container_of(opt, typeof(*ipaddr_opt), opt); struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t *)ptr; int r; - + if (!ipcp->ppp->ses.ipv4) { r = alloc_ip(ipcp->ppp); if (r) return r; } - + opt32->hdr.id = CI_ADDR; opt32->hdr.len = 6; opt32->val = ipcp->ppp->ses.ipv4->addr; @@ -149,7 +149,7 @@ static int ipaddr_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o ipcp->delay_ack = ccp_ipcp_started(ipcp->ppp); return IPCP_OPT_ACK; } - + return IPCP_OPT_NAK; } @@ -163,7 +163,7 @@ static void ipaddr_print(void (*print)(const char *fmt,...),struct ipcp_option_t in.s_addr = opt32->val; else if (ipaddr_opt->ppp->ses.ipv4) in.s_addr = ipaddr_opt->ppp->ses.ipv4->addr; - + print("<addr %s>",inet_ntoa(in)); } diff --git a/accel-pppd/ppp/ipcp_opt_wins.c b/accel-pppd/ppp/ipcp_opt_wins.c index fd69a8cf..c9a3bb5c 100644 --- a/accel-pppd/ppp/ipcp_opt_wins.c +++ b/accel-pppd/ppp/ipcp_opt_wins.c @@ -109,7 +109,7 @@ static int wins_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt if (wins_opt->addr == opt32->val) return IPCP_OPT_ACK; - + return IPCP_OPT_NAK; } @@ -123,7 +123,7 @@ static void wins1_print(void (*print)(const char *fmt, ...), struct ipcp_option_ in.s_addr = opt32->val; else in.s_addr = wins_opt->addr; - + print("<wins1 %s>", inet_ntoa(in)); } @@ -137,7 +137,7 @@ static void wins2_print(void (*print)(const char *fmt, ...), struct ipcp_option_ in.s_addr = opt32->val; else in.s_addr = wins_opt->addr; - + print("<wins2 %s>", inet_ntoa(in)); } @@ -145,7 +145,7 @@ static void ev_wins(struct ev_wins_t *ev) { struct wins_option_t *wins_opt; struct ppp_t *ppp; - + if (!ev->ses->ctrl->ppp) return; @@ -161,11 +161,11 @@ static void ev_wins(struct ev_wins_t *ev) static void load_config(void) { char *opt; - + opt = conf_get_opt("wins", "wins1"); if (opt) conf_wins1 = inet_addr(opt); - + opt = conf_get_opt("wins", "wins2"); if (opt) conf_wins2 = inet_addr(opt); diff --git a/accel-pppd/ppp/ipv6cp_opt_intfid.c b/accel-pppd/ppp/ipv6cp_opt_intfid.c index d2b8127a..aa7afb61 100644 --- a/accel-pppd/ppp/ipv6cp_opt_intfid.c +++ b/accel-pppd/ppp/ipv6cp_opt_intfid.c @@ -159,7 +159,7 @@ static uint64_t generate_intf_id(struct ppp_t *ppp) return id; } - + static uint64_t generate_peer_intf_id(struct ppp_t *ppp) { char str[4]; @@ -168,7 +168,7 @@ static uint64_t generate_peer_intf_id(struct ppp_t *ppp) uint64_t intf_id; uint16_t addr16[4]; } u; - + switch (conf_peer_intf_id) { case INTF_ID_FIXED: return conf_peer_intf_id_val; @@ -204,10 +204,10 @@ static int alloc_ip(struct ppp_t *ppp) if (!ppp->ses.ipv6->intf_id) ppp->ses.ipv6->intf_id = generate_intf_id(ppp); - + if (conf_check_exists && check_exists(ppp)) return IPV6CP_OPT_FAIL; - + return 0; } @@ -216,13 +216,13 @@ static int ipaddr_send_conf_req(struct ppp_ipv6cp_t *ipv6cp, struct ipv6cp_optio struct ipaddr_option_t *ipaddr_opt = container_of(opt, typeof(*ipaddr_opt), opt); struct ipv6cp_opt64_t *opt64 = (struct ipv6cp_opt64_t *)ptr; int r; - + if (!ipv6cp->ppp->ses.ipv6) { r = alloc_ip(ipv6cp->ppp); if (r) return r; } - + opt64->hdr.id = CI_INTFID; opt64->hdr.len = 10; opt64->val = ipv6cp->ppp->ses.ipv6->intf_id; @@ -267,7 +267,7 @@ static int ipaddr_recv_conf_req(struct ppp_ipv6cp_t *ipv6cp, struct ipv6cp_optio ipaddr_opt->started = 1; return IPV6CP_OPT_ACK; } - + return IPV6CP_OPT_NAK; } @@ -281,7 +281,7 @@ static void ipaddr_print(void (*print)(const char *fmt,...), struct ipv6cp_optio *(uint64_t *)(a.s6_addr + 8) = opt64->val; else *(uint64_t *)(a.s6_addr + 8) = ipaddr_opt->ppp->ses.ipv6->intf_id; - + print("<addr %x:%x:%x:%x>", ntohs(a.s6_addr16[4]), ntohs(a.s6_addr16[5]), ntohs(a.s6_addr16[6]), ntohs(a.s6_addr16[7])); } @@ -297,7 +297,7 @@ static uint64_t parse_intfid(const char *opt) if (sscanf(opt, "%x:%x:%x:%x", &n[0], &n[1], &n[2], &n[3]) != 4) goto err; - + for (i = 0; i < 4; i++) { if (n[i] < 0 || n[i] > 0xffff) goto err; @@ -329,7 +329,7 @@ static void load_config(void) conf_intf_id_val = parse_intfid(opt); } } - + opt = conf_get_opt("ppp", "ipv6-peer-intf-id"); if (opt) { if (!strcmp(opt, "random")) @@ -343,7 +343,7 @@ static void load_config(void) conf_peer_intf_id_val = parse_intfid(opt); } } - + opt = conf_get_opt("ppp", "ipv6-accept-peer-intf-id"); if (opt) conf_accept_peer_intf_id = atoi(opt); diff --git a/accel-pppd/ppp/lcp_opt_accomp.c b/accel-pppd/ppp/lcp_opt_accomp.c index 7e605826..f55ed3cf 100644 --- a/accel-pppd/ppp/lcp_opt_accomp.c +++ b/accel-pppd/ppp/lcp_opt_accomp.c @@ -138,7 +138,7 @@ static void accomp_print(void (*print)(const char *fmt, ...), struct lcp_option_ static void load_config(void) { char *opt; - + opt = conf_get_opt("ppp", "accomp"); if (opt) { if (!strcmp(opt, "deny")) diff --git a/accel-pppd/ppp/lcp_opt_magic.c b/accel-pppd/ppp/lcp_opt_magic.c index e2d9bade..52ed26eb 100644 --- a/accel-pppd/ppp/lcp_opt_magic.c +++ b/accel-pppd/ppp/lcp_opt_magic.c @@ -71,7 +71,7 @@ static int magic_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, { struct magic_option_t *magic_opt = container_of(opt, typeof(*magic_opt), opt); struct lcp_opt32_t *opt32 = (struct lcp_opt32_t *)ptr; - + if (!magic_opt->magic) return 0; diff --git a/accel-pppd/ppp/lcp_opt_mru.c b/accel-pppd/ppp/lcp_opt_mru.c index 1cd04f82..c9443312 100644 --- a/accel-pppd/ppp/lcp_opt_mru.c +++ b/accel-pppd/ppp/lcp_opt_mru.c @@ -103,7 +103,7 @@ static int mru_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui /*if (!ptr) return LCP_OPT_NAK;*/ - + if (opt16->hdr.len != 4) return LCP_OPT_REJ; @@ -132,7 +132,7 @@ static int mru_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui if (ioctl(sock_fd, SIOCSIFMTU, &ifr)) log_ppp_error("lcp:mru: failed to set MTU: %s\n", strerror(errno)); - + return 0; } @@ -169,11 +169,11 @@ static void load_config(void) opt = conf_get_opt("ppp", "min-mtu"); if (opt && atoi(opt) > 0) conf_min_mtu = atoi(opt); - + opt = conf_get_opt("ppp", "max-mtu"); if (opt && atoi(opt) > 0) conf_max_mtu = atoi(opt); - + if (conf_min_mtu > conf_mru) { log_emerg("min-mtu cann't be greater then mtu/mru\n"); conf_min_mtu = conf_mru; diff --git a/accel-pppd/ppp/lcp_opt_pcomp.c b/accel-pppd/ppp/lcp_opt_pcomp.c index e034622e..28ca98f9 100644 --- a/accel-pppd/ppp/lcp_opt_pcomp.c +++ b/accel-pppd/ppp/lcp_opt_pcomp.c @@ -138,7 +138,7 @@ static void pcomp_print(void (*print)(const char *fmt, ...), struct lcp_option_t static void load_config(void) { char *opt; - + opt = conf_get_opt("ppp", "pcomp"); if (opt) { if (!strcmp(opt, "deny")) diff --git a/accel-pppd/ppp/ppp_auth.c b/accel-pppd/ppp/ppp_auth.c index 442db7ed..a387ba2d 100644 --- a/accel-pppd/ppp/ppp_auth.c +++ b/accel-pppd/ppp/ppp_auth.c @@ -50,7 +50,7 @@ struct auth_layer_data_t struct ppp_t *ppp; }; -static struct lcp_option_handler_t auth_opt_hnd = +static struct lcp_option_handler_t auth_opt_hnd = { .init = auth_init, .send_conf_req = auth_send_conf_req, @@ -63,7 +63,7 @@ static struct lcp_option_handler_t auth_opt_hnd = .print = auth_print, }; -static struct ppp_layer_t auth_layer = +static struct ppp_layer_t auth_layer = { .init = auth_layer_init, .start = auth_layer_start, @@ -156,7 +156,7 @@ static int auth_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u if (list_empty(&auth_opt->auth_list)) return LCP_OPT_REJ; - + if (!ptr) return LCP_OPT_ACK; @@ -172,7 +172,7 @@ static int auth_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u return r; } } - + list_for_each_entry(d, &auth_opt->auth_list, entry) { if (d->state != LCP_OPT_NAK) { auth_opt->peer_auth = d; @@ -205,7 +205,7 @@ static int auth_recv_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u auth_opt->auth->state = LCP_OPT_NAK; if (auth_opt->peer_auth) auth_opt->auth = auth_opt->peer_auth; - + list_for_each_entry(d, &auth_opt->auth_list, entry) { if (d->state != LCP_OPT_NAK) return 0; @@ -224,11 +224,11 @@ static int auth_recv_conf_rej(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, u log_ppp_error("auth: unexcepcted configure-reject\n"); return -1; } - + auth_opt->auth->state = LCP_OPT_NAK; if (auth_opt->peer_auth) auth_opt->auth = auth_opt->peer_auth; - + list_for_each_entry(d, &auth_opt->auth_list, entry) { if (d->state != LCP_OPT_NAK) return 0; @@ -266,7 +266,7 @@ static struct ppp_layer_data_t *auth_layer_init(struct ppp_t *ppp) struct auth_layer_data_t *ad = _malloc(sizeof(*ad)); log_ppp_debug("auth_layer_init\n"); - + memset(ad, 0, sizeof(*ad)); ad->ppp = ppp; @@ -277,9 +277,9 @@ static struct ppp_layer_data_t *auth_layer_init(struct ppp_t *ppp) static int auth_layer_start(struct ppp_layer_data_t *ld) { struct auth_layer_data_t *ad = container_of(ld,typeof(*ad),ld); - + log_ppp_debug("auth_layer_start\n"); - + if (ad->auth_opt.auth) { ad->auth_opt.started = 1; ad->auth_opt.auth->h->start(ad->ppp, ad->auth_opt.auth); @@ -287,19 +287,19 @@ static int auth_layer_start(struct ppp_layer_data_t *ld) log_ppp_debug("auth_layer_started\n"); ppp_layer_started(ad->ppp, ld); } - + return 0; } static void auth_layer_finish(struct ppp_layer_data_t *ld) { struct auth_layer_data_t *ad = container_of(ld, typeof(*ad), ld); - + log_ppp_debug("auth_layer_finish\n"); - + if (ad->auth_opt.auth) ad->auth_opt.auth->h->finish(ad->ppp, ad->auth_opt.auth); - + ad->auth_opt.started = 0; log_ppp_debug("auth_layer_finished\n"); @@ -375,10 +375,10 @@ int __export ppp_auth_restart(struct ppp_t *ppp) if (!ad->auth_opt.auth->h->restart) return -1; - + if (ad->auth_opt.auth->h->restart(ppp, ad->auth_opt.auth)) return -1; - + return 0; } diff --git a/accel-pppd/ppp/ppp_auth.h b/accel-pppd/ppp/ppp_auth.h index af98262a..5049fd5a 100644 --- a/accel-pppd/ppp/ppp_auth.h +++ b/accel-pppd/ppp/ppp_auth.h @@ -9,7 +9,7 @@ struct auth_data_t { struct list_head entry; int proto; - int state; + int state; struct ppp_auth_handler_t *h; }; diff --git a/accel-pppd/ppp/ppp_ccp.c b/accel-pppd/ppp/ppp_ccp.c index ad6e37e2..ceaccee2 100644 --- a/accel-pppd/ppp/ppp_ccp.c +++ b/accel-pppd/ppp/ppp_ccp.c @@ -79,7 +79,7 @@ static int ccp_set_flags(int fd, int isopen, int isup) log_ppp_error("ccp: failed to get flags: %s\n", strerror(errno)); return -1; } - + flags &= ~(SC_CCP_OPEN | SC_CCP_UP); flags |= (isopen ? SC_CCP_OPEN : 0) | (isup ? SC_CCP_UP : 0); @@ -87,7 +87,7 @@ static int ccp_set_flags(int fd, int isopen, int isup) log_ppp_error("ccp: failed to set flags: %s\n", strerror(errno)); return -1; } - + return 0; } @@ -95,24 +95,24 @@ static struct ppp_layer_data_t *ccp_layer_init(struct ppp_t *ppp) { struct ppp_ccp_t *ccp = _malloc(sizeof(*ccp)); memset(ccp, 0, sizeof(*ccp)); - + log_ppp_debug("ccp_layer_init\n"); ccp->ppp = ppp; ccp->fsm.ppp = ppp; - + ccp->hnd.proto = PPP_CCP; ccp->hnd.recv = ccp_recv; ccp->hnd.recv_proto_rej = ccp_recv_proto_rej; - + ppp_register_unit_handler(ppp, &ccp->hnd); - + ccp->ld.passive = 1; ccp->ld.optional = 1; INIT_LIST_HEAD(&ccp->options); ccp_options_init(ccp); - + ccp->fsm.proto = PPP_CCP; ppp_fsm_init(&ccp->fsm); @@ -136,7 +136,7 @@ static struct ppp_layer_data_t *ccp_layer_init(struct ppp_t *ppp) int ccp_layer_start(struct ppp_layer_data_t *ld) { struct ppp_ccp_t *ccp = container_of(ld, typeof(*ccp), ld); - + log_ppp_debug("ccp_layer_start\n"); ccp_set_flags(ccp->ppp->unit_fd, 0, 0); @@ -154,21 +154,21 @@ int ccp_layer_start(struct ppp_layer_data_t *ld) if (ppp_fsm_open(&ccp->fsm)) return -1; } - + if (ccp_set_flags(ccp->ppp->unit_fd, 1, 0)) { ppp_fsm_close(&ccp->fsm); return -1; } - + return 0; } void ccp_layer_finish(struct ppp_layer_data_t *ld) { struct ppp_ccp_t *ccp = container_of(ld, typeof(*ccp), ld); - + log_ppp_debug("ccp_layer_finish\n"); - + ccp_set_flags(ccp->ppp->unit_fd, 0, 0); ccp->fsm.fsm_state = FSM_Closed; @@ -180,7 +180,7 @@ void ccp_layer_finish(struct ppp_layer_data_t *ld) void ccp_layer_free(struct ppp_layer_data_t *ld) { struct ppp_ccp_t *ccp = container_of(ld, typeof(*ccp), ld); - + log_ppp_debug("ccp_layer_free\n"); ppp_unregister_handler(ccp->ppp, &ccp->hnd); @@ -215,7 +215,7 @@ static void ccp_layer_finished(struct ppp_fsm_t *fsm) ppp_layer_passive(ccp->ppp, &ccp->ld); else if (!ccp->ppp->ses.terminating) ap_session_terminate(&ccp->ppp->ses, TERM_USER_ERROR, 0); - + fsm->fsm_state = FSM_Closed; } @@ -258,12 +258,12 @@ static int send_conf_req(struct ppp_fsm_t *fsm) ccp_hdr->code = CONFREQ; ccp_hdr->id = ccp->fsm.id; ccp_hdr->len = 0; - + ptr = (uint8_t*)(ccp_hdr + 1); if (conf_ppp_verbose) log_ppp_info2("send [CCP ConfReq id=%x", ccp_hdr->id); - + list_for_each_entry(lopt, &ccp->options, entry) { n = lopt->h->send_conf_req(ccp, lopt, ptr); if (n < 0) @@ -276,10 +276,10 @@ static int send_conf_req(struct ppp_fsm_t *fsm) } ptr += n; } - + if (conf_ppp_verbose) log_ppp_info2("]\n"); - + ccp_hdr->len = htons(ptr - buf - 2); ppp_unit_send(ccp->ppp, ccp_hdr, ptr - buf); @@ -315,7 +315,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) ccp_hdr->code = CONFNAK; ccp_hdr->id = ccp->fsm.recv_id; ccp_hdr->len = 0; - + ptr += sizeof(*ccp_hdr); list_for_each_entry(lopt, &ccp->options, entry) { @@ -327,7 +327,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) ptr += lopt->h->send_conf_nak(ccp, lopt, ptr); } } - + if (conf_ppp_verbose) log_ppp_info2("]\n"); @@ -394,7 +394,7 @@ static int ccp_recv_conf_req(struct ppp_ccp_t *ccp, uint8_t *data, int size) ropt = _malloc(sizeof(*ropt)); memset(ropt, 0, sizeof(*ropt)); - + ropt->hdr = hdr; ropt->len = hdr->len; ropt->state = CCP_OPT_NONE; @@ -403,7 +403,7 @@ static int ccp_recv_conf_req(struct ppp_ccp_t *ccp, uint8_t *data, int size) data += hdr->len; size -= hdr->len; } - + if (conf_ppp_verbose) log_ppp_info2("recv [CCP ConfReq id=%x", ccp->fsm.recv_id); @@ -483,7 +483,7 @@ static int ccp_recv_conf_rej(struct ppp_ccp_t *ccp, uint8_t *data, int size) while (size > 0) { hdr = (struct ccp_opt_hdr_t *)data; - + if (!hdr->len || hdr->len > size) break; @@ -524,7 +524,7 @@ static int ccp_recv_conf_nak(struct ppp_ccp_t *ccp, uint8_t *data, int size) while (size > 0) { hdr = (struct ccp_opt_hdr_t *)data; - + if (!hdr->len || hdr->len > size) break; @@ -567,7 +567,7 @@ static int ccp_recv_conf_ack(struct ppp_ccp_t *ccp, uint8_t *data, int size) while (size > 0) { hdr = (struct ccp_opt_hdr_t *)data; - + if (!hdr->len || hdr->len > size) break; @@ -656,9 +656,9 @@ static void ccp_recv(struct ppp_handler_t*h) return; ccp->fsm.recv_id = hdr->id; - + switch(hdr->code) { - case CONFREQ: + case CONFREQ: r = ccp_recv_conf_req(ccp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); if (ccp->ld.passive) { ccp->ld.passive = 0; @@ -684,7 +684,7 @@ static void ccp_recv(struct ppp_handler_t*h) } } ccp_free_conf_req(ccp); - + if (r == CCP_OPT_FAIL) ap_session_terminate(&ccp->ppp->ses, TERM_USER_ERROR, 0); break; @@ -738,7 +738,7 @@ static void ccp_recv_proto_rej(struct ppp_handler_t *h) if (ccp->fsm.fsm_state == FSM_Initial || ccp->fsm.fsm_state == FSM_Closed) return; - + ppp_fsm_lower_down(&ccp->fsm); ppp_fsm_close(&ccp->fsm); } @@ -748,9 +748,9 @@ int ccp_option_register(struct ccp_option_handler_t *h) /*struct ccp_option_drv_t *p; list_for_each_entry(p,option_drv_list,entry) - if (p->id==h->id) + if (p->id==h->id) return -1;*/ - + list_add_tail(&h->entry,&option_handlers); return 0; @@ -764,11 +764,11 @@ struct ccp_option_t *ccp_find_option(struct ppp_t *ppp, struct ccp_option_handle { struct ppp_ccp_t *ccp = container_of(ppp_find_layer_data(ppp, &ccp_layer), typeof(*ccp), ld); struct ccp_option_t *opt; - + list_for_each_entry(opt, &ccp->options, entry) if (opt->h == h) return opt; - + log_emerg("ccp: BUG: option not found\n"); abort(); } @@ -795,7 +795,7 @@ static void load_config(void) opt = conf_get_opt("ppp", "ccp"); if (opt && atoi(opt) >= 0) conf_ccp = atoi(opt); - + opt = conf_get_opt("ppp", "ccp-max-configure"); if (opt && atoi(opt) > 0) conf_ccp_max_configure = atoi(opt); diff --git a/accel-pppd/ppp/ppp_ccp.h b/accel-pppd/ppp/ppp_ccp.h index acc56ff0..cb5b1644 100644 --- a/accel-pppd/ppp/ppp_ccp.h +++ b/accel-pppd/ppp/ppp_ccp.h @@ -82,7 +82,7 @@ struct ppp_ccp_t struct list_head ropt_list; // last received ConfReq int ropt_len; - + int conf_req_len; int starting:1; int started:1; diff --git a/accel-pppd/ppp/ppp_fsm.c b/accel-pppd/ppp/ppp_fsm.c index b0331d90..bb45d5cb 100644 --- a/accel-pppd/ppp/ppp_fsm.c +++ b/accel-pppd/ppp/ppp_fsm.c @@ -54,7 +54,7 @@ int ppp_fsm_lower_up(struct ppp_fsm_t *layer) //if (layer->init_req_cnt) layer->init_req_cnt(layer); init_req_counter(layer,layer->max_configure); --layer->restart_counter; - if (layer->send_conf_req) + if (layer->send_conf_req) if (layer->send_conf_req(layer)) return -1; layer->fsm_state=FSM_Req_Sent; @@ -509,7 +509,7 @@ static void init_req_counter(struct ppp_fsm_t *layer,int timeout) static void zero_req_counter(struct ppp_fsm_t *layer) { layer->restart_counter=0; - + if (!layer->restart_timer.tpd) triton_timer_add(layer->ppp->ses.ctrl->ctx, &layer->restart_timer, 0); } diff --git a/accel-pppd/ppp/ppp_fsm.h b/accel-pppd/ppp/ppp_fsm.h index 95da7b63..57abb869 100644 --- a/accel-pppd/ppp/ppp_fsm.h +++ b/accel-pppd/ppp/ppp_fsm.h @@ -25,7 +25,7 @@ struct ppp_fsm_t struct ppp_t *ppp; FSM_STATE fsm_state; uint16_t proto; - + struct triton_timer_t restart_timer; int restart_counter; int max_terminate; diff --git a/accel-pppd/ppp/ppp_ifcfg.c b/accel-pppd/ppp/ppp_ifcfg.c index aa2aff7b..f6eba064 100644 --- a/accel-pppd/ppp/ppp_ifcfg.c +++ b/accel-pppd/ppp/ppp_ifcfg.c @@ -21,7 +21,7 @@ struct in6_ifreq { struct in6_addr ifr6_addr; __u32 ifr6_prefixlen; - int ifr6_ifindex; + int ifr6_ifindex; }; static void devconf(struct ppp_t *ppp, const char *attr, const char *val) @@ -58,7 +58,7 @@ void ppp_ifup(struct ppp_t *ppp) struct in6_ifreq ifr6; struct npioctl np; struct sockaddr_in addr; - + triton_event_fire(EV_SES_ACCT_START, ppp); if (ppp->stop_time) return; @@ -69,19 +69,19 @@ void ppp_ifup(struct ppp_t *ppp) memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, ppp->ifname); - + if (ppp->ses.ipv4) { memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = ppp->ses.ipv4->addr; memcpy(&ifr.ifr_addr,&addr,sizeof(addr)); - + if (ioctl(sock_fd, SIOCSIFADDR, &ifr)) log_ppp_error("ppp: failed to set IPv4 address: %s\n", strerror(errno)); - + addr.sin_addr.s_addr = ppp->ses.ipv4->peer_addr; memcpy(&ifr.ifr_dstaddr,&addr,sizeof(addr)); - + if (ioctl(sock_fd, SIOCSIFDSTADDR, &ifr)) log_ppp_error("ppp: failed to set peer IPv4 address: %s\n", strerror(errno)); } @@ -99,7 +99,7 @@ void ppp_ifup(struct ppp_t *ppp) if (ioctl(sock6_fd, SIOCSIFADDR, &ifr6)) log_ppp_error("ppp: failed to set LL IPv6 address: %s\n", strerror(errno)); - + list_for_each_entry(a, &ppp->ses.ipv6->addr_list, entry) { if (a->prefix_len == 128) continue; @@ -127,7 +127,7 @@ void ppp_ifup(struct ppp_t *ppp) if (ioctl(ppp->unit_fd, PPPIOCSNPMODE, &np)) log_ppp_error("ppp: failed to set NP (IPv4) mode: %s\n", strerror(errno)); } - + if (ppp->ses.ipv6) { np.protocol = PPP_IPV6; np.mode = NPMODE_PASS; @@ -135,7 +135,7 @@ void ppp_ifup(struct ppp_t *ppp) if (ioctl(ppp->unit_fd, PPPIOCSNPMODE, &np)) log_ppp_error("ppp: failed to set NP (IPv6) mode: %s\n", strerror(errno)); } - + ppp->ses.ctrl->started(ppp); triton_event_fire(EV_SES_STARTED, ppp); @@ -167,7 +167,7 @@ void __export ppp_ifdown(struct ppp_t *ppp) ifr6.ifr6_ifindex = ppp->ifindex; ioctl(sock6_fd, SIOCDIFADDR, &ifr6); - + list_for_each_entry(a, &ppp->ses.ipv6->addr_list, entry) { if (a->prefix_len == 128) continue; diff --git a/accel-pppd/ppp/ppp_ipcp.c b/accel-pppd/ppp/ppp_ipcp.c index 6cb86a4b..416fba93 100644 --- a/accel-pppd/ppp/ppp_ipcp.c +++ b/accel-pppd/ppp/ppp_ipcp.c @@ -54,7 +54,7 @@ static void ipcp_options_init(struct ppp_ipcp_t *ipcp) struct ipcp_option_handler_t *h; ipcp->conf_req_len = sizeof(struct ipcp_hdr_t); - + list_for_each_entry(h,&option_handlers,entry) { lopt = h->init(ipcp); if (lopt) { @@ -80,16 +80,16 @@ static struct ppp_layer_data_t *ipcp_layer_init(struct ppp_t *ppp) { struct ppp_ipcp_t *ipcp = _malloc(sizeof(*ipcp)); memset(ipcp, 0, sizeof(*ipcp)); - + log_ppp_debug("ipcp_layer_init\n"); ipcp->ppp = ppp; ipcp->fsm.ppp = ppp; - + ipcp->hnd.proto = PPP_IPCP; ipcp->hnd.recv = ipcp_recv; ipcp->hnd.recv_proto_rej = ipcp_recv_proto_rej; - + ppp_register_unit_handler(ppp, &ipcp->hnd); INIT_LIST_HEAD(&ipcp->options); @@ -111,7 +111,7 @@ static struct ppp_layer_data_t *ipcp_layer_init(struct ppp_t *ppp) INIT_LIST_HEAD(&ipcp->ropt_list); ipcp->ld.passive = conf_ipv4 == IPV4_ALLOW || conf_ipv4 == IPV4_DENY; - + return &ipcp->ld; } @@ -128,7 +128,7 @@ static void ipcp_start_timeout(struct triton_timer_t *t) int ipcp_layer_start(struct ppp_layer_data_t *ld) { struct ppp_ipcp_t *ipcp = container_of(ld, typeof(*ipcp), ld); - + log_ppp_debug("ipcp_layer_start\n"); ipcp->starting = 1; @@ -144,18 +144,18 @@ int ipcp_layer_start(struct ppp_layer_data_t *ld) return -1; } } - + return 0; } void ipcp_layer_finish(struct ppp_layer_data_t *ld) { struct ppp_ipcp_t *ipcp = container_of(ld, typeof(*ipcp), ld); - + log_ppp_debug("ipcp_layer_finish\n"); ipcp->fsm.fsm_state = FSM_Closed; - + log_ppp_debug("ipcp_layer_finished\n"); ppp_layer_finished(ipcp->ppp, &ipcp->ld); } @@ -163,9 +163,9 @@ void ipcp_layer_finish(struct ppp_layer_data_t *ld) void ipcp_layer_free(struct ppp_layer_data_t *ld) { struct ppp_ipcp_t *ipcp = container_of(ld, typeof(*ipcp), ld); - + log_ppp_debug("ipcp_layer_free\n"); - + ppp_unregister_handler(ipcp->ppp, &ipcp->hnd); ipcp_options_free(ipcp); ppp_fsm_free(&ipcp->fsm); @@ -189,7 +189,7 @@ static void __ipcp_layer_up(struct ppp_ipcp_t *ipcp) static void ipcp_layer_up(struct ppp_fsm_t *fsm) { struct ppp_ipcp_t *ipcp = container_of(fsm, typeof(*ipcp), fsm); - + if (!ipcp->delay_ack) __ipcp_layer_up(ipcp); } @@ -207,7 +207,7 @@ static void ipcp_layer_finished(struct ppp_fsm_t *fsm) ppp_layer_passive(ipcp->ppp, &ipcp->ld); } else if (!ipcp->ppp->ses.terminating) ap_session_terminate(&ipcp->ppp->ses, TERM_USER_ERROR, 0); - + fsm->fsm_state = FSM_Closed; } @@ -244,7 +244,7 @@ static int send_conf_req(struct ppp_fsm_t *fsm) ipcp_hdr->code = CONFREQ; ipcp_hdr->id = ipcp->fsm.id; ipcp_hdr->len = 0; - + ptr += sizeof(*ipcp_hdr); list_for_each_entry(lopt, &ipcp->options, entry) { @@ -318,7 +318,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) ipcp_hdr->code = CONFNAK; ipcp_hdr->id = ipcp->fsm.recv_id; ipcp_hdr->len = 0; - + ptr += sizeof(*ipcp_hdr); list_for_each_entry(ropt, &ipcp->ropt_list, entry) { @@ -331,7 +331,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) } } } - + if (conf_ppp_verbose) log_ppp_info2("]\n"); @@ -407,7 +407,7 @@ static int ipcp_recv_conf_req(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) data += hdr->len; size -= hdr->len; } - + list_for_each_entry(lopt, &ipcp->options, entry) lopt->state=IPCP_OPT_NONE; @@ -454,7 +454,7 @@ static int ipcp_recv_conf_req(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) if (r < ret) ret = r; break; - } + } } if (!ropt->lopt) { ropt->state = IPCP_OPT_REJ; @@ -504,7 +504,7 @@ static int ipcp_recv_conf_rej(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) while (size > 0) { hdr = (struct ipcp_opt_hdr_t *)data; - + if (!hdr->len || hdr->len > size) break; @@ -545,7 +545,7 @@ static int ipcp_recv_conf_nak(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) while (size > 0) { hdr = (struct ipcp_opt_hdr_t *)data; - + if (!hdr->len || hdr->len > size) break; @@ -588,7 +588,7 @@ static int ipcp_recv_conf_ack(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) while (size > 0) { hdr = (struct ipcp_opt_hdr_t *)data; - + if (!hdr->len || hdr->len > size) break; @@ -644,7 +644,7 @@ static void send_term_ack(struct ppp_fsm_t *fsm) if (conf_ppp_verbose) log_ppp_info2("send [IPCP TermAck id=%x]\n", hdr.id); - + ppp_unit_send(ipcp->ppp, &hdr, 6); } @@ -675,12 +675,12 @@ static void ipcp_recv(struct ppp_handler_t*h) log_ppp_warn("IPCP: short packet received\n"); return; } - + if ((hdr->code == CONFACK || hdr->code == CONFNAK || hdr->code == CONFREJ) && hdr->id != ipcp->fsm.id) return; ipcp->fsm.recv_id = hdr->id; - + switch(hdr->code) { case CONFREQ: r = ipcp_recv_conf_req(ipcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); @@ -763,7 +763,7 @@ static void ipcp_recv_proto_rej(struct ppp_handler_t*h) if (ipcp->fsm.fsm_state == FSM_Initial || ipcp->fsm.fsm_state == FSM_Closed) return; - + ppp_fsm_lower_down(&ipcp->fsm); ppp_fsm_close(&ipcp->fsm); } @@ -773,9 +773,9 @@ int ipcp_option_register(struct ipcp_option_handler_t *h) /*struct ipcp_option_drv_t *p; list_for_each_entry(p,option_drv_list,entry) - if (p->id==h->id) + if (p->id==h->id) return -1;*/ - + list_add_tail(&h->entry, &option_handlers); return 0; @@ -785,11 +785,11 @@ struct ipcp_option_t *ipcp_find_option(struct ppp_t *ppp, struct ipcp_option_han { struct ppp_ipcp_t *ipcp = container_of(ppp_find_layer_data(ppp, &ipcp_layer), typeof(*ipcp), ld); struct ipcp_option_t *opt; - + list_for_each_entry(opt, &ipcp->options, entry) if (opt->h == h) return opt; - + log_emerg("ipcp: BUG: option not found\n"); abort(); } diff --git a/accel-pppd/ppp/ppp_ipcp.h b/accel-pppd/ppp/ppp_ipcp.h index 74127020..a46d9b6d 100644 --- a/accel-pppd/ppp/ppp_ipcp.h +++ b/accel-pppd/ppp/ppp_ipcp.h @@ -91,7 +91,7 @@ struct ppp_ipcp_t struct list_head ropt_list; // last received ConfReq int ropt_len; - + int conf_req_len; int starting:1; int started:1; diff --git a/accel-pppd/ppp/ppp_ipv6cp.c b/accel-pppd/ppp/ppp_ipv6cp.c index 9a879227..1194b314 100644 --- a/accel-pppd/ppp/ppp_ipv6cp.c +++ b/accel-pppd/ppp/ppp_ipv6cp.c @@ -54,7 +54,7 @@ static void ipv6cp_options_init(struct ppp_ipv6cp_t *ipv6cp) struct ipv6cp_option_handler_t *h; ipv6cp->conf_req_len = sizeof(struct ipv6cp_hdr_t); - + list_for_each_entry(h,&option_handlers,entry) { lopt = h->init(ipv6cp); if (lopt) { @@ -80,16 +80,16 @@ static struct ppp_layer_data_t *ipv6cp_layer_init(struct ppp_t *ppp) { struct ppp_ipv6cp_t *ipv6cp = _malloc(sizeof(*ipv6cp)); memset(ipv6cp, 0, sizeof(*ipv6cp)); - + log_ppp_debug("ipv6cp_layer_init\n"); ipv6cp->ppp = ppp; ipv6cp->fsm.ppp = ppp; - + ipv6cp->hnd.proto = PPP_IPV6CP; ipv6cp->hnd.recv = ipv6cp_recv; ipv6cp->hnd.recv_proto_rej = ipv6cp_recv_proto_rej; - + ppp_register_unit_handler(ppp, &ipv6cp->hnd); ipv6cp->fsm.proto = PPP_IPV6CP; @@ -109,7 +109,7 @@ static struct ppp_layer_data_t *ipv6cp_layer_init(struct ppp_t *ppp) INIT_LIST_HEAD(&ipv6cp->ropt_list); ipv6cp->ld.passive = conf_ipv6 == IPV6_ALLOW || conf_ipv6 == IPV6_DENY; - + return &ipv6cp->ld; } @@ -118,7 +118,7 @@ static void ipv6cp_start_timeout(struct triton_timer_t *t) struct ppp_ipv6cp_t *ipv6cp = container_of(t, typeof(*ipv6cp), timeout); triton_timer_del(t); - + if (ipv6cp->ppp->ses.state == AP_STATE_STARTING) ap_session_terminate(&ipv6cp->ppp->ses, TERM_USER_ERROR, 0); } @@ -126,7 +126,7 @@ static void ipv6cp_start_timeout(struct triton_timer_t *t) int ipv6cp_layer_start(struct ppp_layer_data_t *ld) { struct ppp_ipv6cp_t *ipv6cp = container_of(ld, typeof(*ipv6cp), ld); - + log_ppp_debug("ipv6cp_layer_start\n"); ipv6cp_options_init(ipv6cp); @@ -144,18 +144,18 @@ int ipv6cp_layer_start(struct ppp_layer_data_t *ld) return -1; } } - + return 0; } void ipv6cp_layer_finish(struct ppp_layer_data_t *ld) { struct ppp_ipv6cp_t *ipv6cp = container_of(ld, typeof(*ipv6cp), ld); - + log_ppp_debug("ipv6cp_layer_finish\n"); ipv6cp->fsm.fsm_state = FSM_Closed; - + log_ppp_debug("ipv6cp_layer_finished\n"); ppp_layer_finished(ipv6cp->ppp, &ipv6cp->ld); } @@ -163,9 +163,9 @@ void ipv6cp_layer_finish(struct ppp_layer_data_t *ld) void ipv6cp_layer_free(struct ppp_layer_data_t *ld) { struct ppp_ipv6cp_t *ipv6cp = container_of(ld, typeof(*ipv6cp), ld); - + log_ppp_debug("ipv6cp_layer_free\n"); - + ppp_unregister_handler(ipv6cp->ppp, &ipv6cp->hnd); ipv6cp_options_free(ipv6cp); ppp_fsm_free(&ipv6cp->fsm); @@ -189,7 +189,7 @@ static void __ipv6cp_layer_up(struct ppp_ipv6cp_t *ipv6cp) static void ipv6cp_layer_up(struct ppp_fsm_t *fsm) { struct ppp_ipv6cp_t *ipv6cp = container_of(fsm, typeof(*ipv6cp), fsm); - + if (!ipv6cp->delay_ack) __ipv6cp_layer_up(ipv6cp); } @@ -207,7 +207,7 @@ static void ipv6cp_layer_finished(struct ppp_fsm_t *fsm) ppp_layer_passive(ipv6cp->ppp, &ipv6cp->ld); } else if (!ipv6cp->ppp->ses.terminating) ap_session_terminate(&ipv6cp->ppp->ses, TERM_USER_ERROR, 0); - + fsm->fsm_state = FSM_Closed; } @@ -244,7 +244,7 @@ static int send_conf_req(struct ppp_fsm_t *fsm) ipv6cp_hdr->code = CONFREQ; ipv6cp_hdr->id = ipv6cp->fsm.id; ipv6cp_hdr->len = 0; - + ptr += sizeof(*ipv6cp_hdr); list_for_each_entry(lopt, &ipv6cp->options, entry) { @@ -318,7 +318,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) ipv6cp_hdr->code = CONFNAK; ipv6cp_hdr->id = ipv6cp->fsm.recv_id; ipv6cp_hdr->len = 0; - + ptr += sizeof(*ipv6cp_hdr); list_for_each_entry(ropt, &ipv6cp->ropt_list, entry) { @@ -331,7 +331,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) } } } - + if (conf_ppp_verbose) log_ppp_info2("]\n"); @@ -407,7 +407,7 @@ static int ipv6cp_recv_conf_req(struct ppp_ipv6cp_t *ipv6cp, uint8_t *data, int data += hdr->len; size -= hdr->len; } - + list_for_each_entry(lopt, &ipv6cp->options, entry) lopt->state=IPV6CP_OPT_NONE; @@ -454,7 +454,7 @@ static int ipv6cp_recv_conf_req(struct ppp_ipv6cp_t *ipv6cp, uint8_t *data, int if (r < ret) ret = r; break; - } + } } if (!ropt->lopt) { ropt->state = IPV6CP_OPT_REJ; @@ -504,7 +504,7 @@ static int ipv6cp_recv_conf_rej(struct ppp_ipv6cp_t *ipv6cp, uint8_t *data, int while (size > 0) { hdr = (struct ipv6cp_opt_hdr_t *)data; - + if (!hdr->len || hdr->len > size) break; @@ -545,7 +545,7 @@ static int ipv6cp_recv_conf_nak(struct ppp_ipv6cp_t *ipv6cp, uint8_t *data, int while (size > 0) { hdr = (struct ipv6cp_opt_hdr_t *)data; - + if (!hdr->len || hdr->len > size) break; @@ -588,7 +588,7 @@ static int ipv6cp_recv_conf_ack(struct ppp_ipv6cp_t *ipv6cp, uint8_t *data, int while (size > 0) { hdr = (struct ipv6cp_opt_hdr_t *)data; - + if (!hdr->len || hdr->len > size) break; @@ -644,7 +644,7 @@ static void send_term_ack(struct ppp_fsm_t *fsm) if (conf_ppp_verbose) log_ppp_info2("send [IPV6CP TermAck id=%x]\n", hdr.id); - + ppp_unit_send(ipv6cp->ppp, &hdr, 6); } @@ -675,12 +675,12 @@ static void ipv6cp_recv(struct ppp_handler_t*h) log_ppp_warn("IPV6CP: short packet received\n"); return; } - + if ((hdr->code == CONFACK || hdr->code == CONFNAK || hdr->code == CONFREJ) && hdr->id != ipv6cp->fsm.id) return; ipv6cp->fsm.recv_id = hdr->id; - + switch(hdr->code) { case CONFREQ: r = ipv6cp_recv_conf_req(ipv6cp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); @@ -763,7 +763,7 @@ static void ipv6cp_recv_proto_rej(struct ppp_handler_t*h) if (ipv6cp->fsm.fsm_state == FSM_Initial || ipv6cp->fsm.fsm_state == FSM_Closed) return; - + ppp_fsm_lower_down(&ipv6cp->fsm); ppp_fsm_close(&ipv6cp->fsm); } @@ -773,9 +773,9 @@ int ipv6cp_option_register(struct ipv6cp_option_handler_t *h) /*struct ipv6cp_option_drv_t *p; list_for_each_entry(p,option_drv_list,entry) - if (p->id==h->id) + if (p->id==h->id) return -1;*/ - + list_add_tail(&h->entry, &option_handlers); return 0; @@ -785,11 +785,11 @@ struct ipv6cp_option_t *ipv6cp_find_option(struct ppp_t *ppp, struct ipv6cp_opti { struct ppp_ipv6cp_t *ipv6cp = container_of(ppp_find_layer_data(ppp, &ipv6cp_layer), typeof(*ipv6cp), ld); struct ipv6cp_option_t *opt; - + list_for_each_entry(opt, &ipv6cp->options, entry) if (opt->h == h) return opt; - + log_emerg("ipv6cp: BUG: option not found\n"); abort(); } diff --git a/accel-pppd/ppp/ppp_ipv6cp.h b/accel-pppd/ppp/ppp_ipv6cp.h index 6f676053..57bb73b4 100644 --- a/accel-pppd/ppp/ppp_ipv6cp.h +++ b/accel-pppd/ppp/ppp_ipv6cp.h @@ -97,7 +97,7 @@ struct ppp_ipv6cp_t struct list_head ropt_list; // last received ConfReq int ropt_len; - + int conf_req_len; int starting:1; int started:1; diff --git a/accel-pppd/ppp/ppp_lcp.c b/accel-pppd/ppp/ppp_lcp.c index 3dd8708b..2641cf34 100644 --- a/accel-pppd/ppp/ppp_lcp.c +++ b/accel-pppd/ppp/ppp_lcp.c @@ -80,15 +80,15 @@ static struct ppp_layer_data_t *lcp_layer_init(struct ppp_t *ppp) { struct ppp_lcp_t *lcp = _malloc(sizeof(*lcp)); memset(lcp, 0, sizeof(*lcp)); - + log_ppp_debug("lcp_layer_init\n"); lcp->ppp = ppp; lcp->fsm.ppp = ppp; - + lcp->hnd.proto = PPP_LCP; lcp->hnd.recv = lcp_recv; - + ppp_register_chan_handler(ppp, &lcp->hnd); lcp->fsm.proto = PPP_LCP; @@ -113,14 +113,14 @@ static struct ppp_layer_data_t *lcp_layer_init(struct ppp_t *ppp) int lcp_layer_start(struct ppp_layer_data_t *ld) { struct ppp_lcp_t *lcp = container_of(ld, typeof(*lcp), ld); - + log_ppp_debug("lcp_layer_start\n"); lcp_options_init(lcp); ppp_fsm_lower_up(&lcp->fsm); if (ppp_fsm_open(&lcp->fsm)) return -1; - + return 0; } @@ -132,7 +132,7 @@ static void _lcp_layer_finished(struct ppp_lcp_t *lcp) void lcp_layer_finish(struct ppp_layer_data_t *ld) { struct ppp_lcp_t *lcp = container_of(ld,typeof(*lcp),ld); - + log_ppp_debug("lcp_layer_finish\n"); if (lcp->started) { @@ -145,7 +145,7 @@ void lcp_layer_finish(struct ppp_layer_data_t *ld) void lcp_layer_free(struct ppp_layer_data_t *ld) { struct ppp_lcp_t *lcp = container_of(ld, typeof(*lcp), ld); - + log_ppp_debug("lcp_layer_free\n"); stop_echo(lcp); @@ -153,7 +153,7 @@ void lcp_layer_free(struct ppp_layer_data_t *ld) lcp_options_free(lcp); ppp_fsm_free(&lcp->fsm); triton_cancel_call(lcp->ppp->ses.ctrl->ctx, (triton_event_func)_lcp_layer_finished); - + _free(lcp); } @@ -219,7 +219,7 @@ static int send_conf_req(struct ppp_fsm_t *fsm) lcp_hdr->code = CONFREQ; lcp_hdr->id = lcp->fsm.id; lcp_hdr->len = 0; - + ptr += sizeof(*lcp_hdr); list_for_each_entry(lopt, &lcp->options, entry) { @@ -232,7 +232,7 @@ static int send_conf_req(struct ppp_fsm_t *fsm) } else lopt->print = 0; } - + if (conf_ppp_verbose) { log_ppp_info2("send [LCP ConfReq id=%x", lcp_hdr->id); list_for_each_entry(lopt,&lcp->options,entry) { @@ -293,13 +293,13 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) lcp_hdr->code = CONFNAK; lcp_hdr->id = lcp->fsm.recv_id; lcp_hdr->len = 0; - + ptr += sizeof(*lcp_hdr); list_for_each_entry(lopt, &lcp->options, entry) { if (lopt->state == LCP_OPT_NAK) { n = lopt->h->send_conf_nak(lcp, lopt, ptr); - + if (conf_ppp_verbose && n) { log_ppp_info2(" "); lopt->h->print(log_ppp_info2, lopt, ptr); @@ -308,7 +308,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) ptr += n; } } - + if (conf_ppp_verbose) log_ppp_info2("]\n"); @@ -385,7 +385,7 @@ static int lcp_recv_conf_req(struct ppp_lcp_t *lcp, uint8_t *data, int size) data += hdr->len; size -= hdr->len; } - + list_for_each_entry(lopt, &lcp->options, entry) lopt->state = LCP_OPT_NONE; @@ -465,7 +465,7 @@ static int lcp_recv_conf_rej(struct ppp_lcp_t *lcp, uint8_t *data, int size) if (!hdr->len || hdr->len > size) break; - + list_for_each_entry(lopt, &lcp->options, entry) { if (lopt->id == hdr->id) { if (conf_ppp_verbose) { @@ -510,7 +510,7 @@ static int lcp_recv_conf_nak(struct ppp_lcp_t *lcp, uint8_t *data, int size) if (!hdr->len || hdr->len > size) break; - + list_for_each_entry(lopt,&lcp->options,entry) { if (lopt->id == hdr->id) { if (conf_ppp_verbose) { @@ -553,7 +553,7 @@ static int lcp_recv_conf_ack(struct ppp_lcp_t *lcp, uint8_t *data, int size) if (!hdr->len || hdr->len > size) break; - + list_for_each_entry(lopt, &lcp->options, entry) { if (lopt->id == hdr->id) { if (conf_ppp_verbose) { @@ -730,7 +730,7 @@ static void send_term_ack(struct ppp_fsm_t *fsm) if (conf_ppp_verbose) log_ppp_info2("send [LCP TermAck id=%i]\n", hdr.id); - + ppp_chan_send(lcp->ppp, &hdr, 6); } @@ -761,13 +761,13 @@ static void lcp_recv(struct ppp_handler_t*h) struct ppp_lcp_t *lcp = container_of(h, typeof(*lcp), hnd); int r; char *term_msg; - + if (lcp->ppp->buf_size < PPP_HEADERLEN + 2) { log_ppp_warn("LCP: short packet received\n"); return; } - hdr = (struct lcp_hdr_t *)lcp->ppp->buf; + hdr = (struct lcp_hdr_t *)lcp->ppp->buf; if (ntohs(hdr->len) < PPP_HEADERLEN) { log_ppp_warn("LCP: short packet received\n"); return; @@ -775,7 +775,7 @@ static void lcp_recv(struct ppp_handler_t*h) if ((hdr->code == CONFACK || hdr->code == CONFNAK || hdr->code == CONFREJ) && hdr->id != lcp->fsm.id) return; - + if ((hdr->code == CONFACK || hdr->code == CONFNAK || hdr->code == CONFREJ) && lcp->started) return; @@ -887,9 +887,9 @@ int lcp_option_register(struct lcp_option_handler_t *h) /*struct lcp_option_drv_t *p; list_for_each_entry(p,option_drv_list,entry) - if (p->id==h->id) + if (p->id==h->id) return -1;*/ - + list_add_tail(&h->entry, &option_handlers); return 0; @@ -922,7 +922,7 @@ static void load_config(void) opt = conf_get_opt("ppp", "lcp-echo-failure"); if (opt && atoi(opt) >= 0) conf_echo_failure = atoi(opt); - + opt = conf_get_opt("ppp", "lcp-echo-timeout"); if (opt && atoi(opt) >= 0) conf_echo_timeout = atoi(opt); diff --git a/accel-pppd/ppp/ppp_lcp.h b/accel-pppd/ppp/ppp_lcp.h index 465f0e9a..cfc81229 100644 --- a/accel-pppd/ppp/ppp_lcp.h +++ b/accel-pppd/ppp/ppp_lcp.h @@ -125,7 +125,7 @@ struct ppp_lcp_t struct list_head ropt_list; // last received ConfReq int ropt_len; - + int conf_req_len; int started:1; }; diff --git a/accel-pppd/ppp/ppp_pd.c b/accel-pppd/ppp/ppp_pd.c index f7702083..c33ae968 100644 --- a/accel-pppd/ppp/ppp_pd.c +++ b/accel-pppd/ppp/ppp_pd.c @@ -9,6 +9,6 @@ int ppp_store_pd(struct ppp_t *ppp, pd_key_t key, void *data) list_for_each_entry(pd, &ppp->pd_list, entry) if (pd->key == key) return -1; - + } diff --git a/accel-pppd/radius/acct.c b/accel-pppd/radius/acct.c index 7ac6e394..3d194474 100644 --- a/accel-pppd/radius/acct.c +++ b/accel-pppd/radius/acct.c @@ -23,7 +23,7 @@ static int req_set_RA(struct rad_req_t *req, const char *secret) { MD5_CTX ctx; - + if (rad_packet_build(req->pack, req->RA)) return -1; @@ -41,7 +41,7 @@ static int req_set_stat(struct rad_req_t *req, struct ap_session *ses) struct radius_pd_t *rpd = req->rpd; struct timespec ts; int ret = 0; - + if (ses->stop_time) ts.tv_sec = ses->stop_time; else @@ -68,7 +68,7 @@ static void rad_acct_sent(struct rad_req_t *req, int res) return; __sync_add_and_fetch(&req->serv->stat_interim_sent, 1); - + if (!req->hnd.tpd) triton_md_register_handler(req->rpd->ses->ctrl->ctx, &req->hnd); @@ -82,7 +82,7 @@ static void rad_acct_sent(struct rad_req_t *req, int res) static void rad_acct_recv(struct rad_req_t *req) { - int dt = (req->reply->tv.tv_sec - req->pack->tv.tv_sec) * 1000 + + int dt = (req->reply->tv.tv_sec - req->pack->tv.tv_sec) * 1000 + (req->reply->tv.tv_nsec - req->pack->tv.tv_nsec) / 1000000; stat_accm_add(req->serv->stat_interim_query_1m, dt); @@ -91,7 +91,7 @@ static void rad_acct_recv(struct rad_req_t *req) triton_timer_del(&req->timeout); triton_md_unregister_handler(&req->hnd, 1); - + rad_packet_free(req->reply); req->reply = NULL; } @@ -101,7 +101,7 @@ static void rad_acct_timeout(struct triton_timer_t *t) struct rad_req_t *req = container_of(t, typeof(*req), timeout); time_t dt; struct timespec ts; - + rad_server_req_exit(req); rad_server_timeout(req->serv); @@ -134,8 +134,8 @@ static void rad_acct_timeout(struct triton_timer_t *t) } if (conf_acct_delay_time) - req->pack->id++; - + req->pack->id++; + req->try = 0; if (rad_req_send(req) && conf_acct_timeout) { @@ -152,7 +152,7 @@ static void rad_acct_interim_update(struct triton_timer_t *t) if (rpd->acct_req->entry.next || rpd->acct_req->timeout.tpd) return; - if (rpd->session_timeout.expire_tv.tv_sec && + if (rpd->session_timeout.expire_tv.tv_sec && rpd->session_timeout.expire_tv.tv_sec - (_time() - rpd->ses->start_time) < INTERIM_SAFE_TIME) return; @@ -170,7 +170,7 @@ static void rad_acct_interim_update(struct triton_timer_t *t) if (!rpd->acct_req->before_send) req_set_RA(rpd->acct_req, rpd->acct_req->serv->secret); - + rpd->acct_req->timeout.expire_tv.tv_sec = conf_timeout; rpd->acct_req->try = 0; @@ -185,7 +185,7 @@ static int rad_acct_before_send(struct rad_req_t *req) struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - + rad_packet_change_int(req->pack, NULL, "Acct-Delay-Time", ts.tv_sec - req->ts); req_set_RA(req, req->serv->secret); @@ -198,12 +198,12 @@ static void rad_acct_start_sent(struct rad_req_t *req, int res) ap_session_terminate(req->rpd->ses, TERM_NAS_ERROR, 0); return; } - + __sync_add_and_fetch(&req->serv->stat_acct_sent, 1); - + if (!req->hnd.tpd) triton_md_register_handler(req->rpd->ses->ctrl->ctx, &req->hnd); - + triton_md_enable_handler(&req->hnd, MD_MODE_READ); if (req->timeout.tpd) @@ -215,7 +215,7 @@ static void rad_acct_start_sent(struct rad_req_t *req, int res) static void rad_acct_start_recv(struct rad_req_t *req) { struct radius_pd_t *rpd = req->rpd; - int dt = (req->reply->tv.tv_sec - req->pack->tv.tv_sec) * 1000 + + int dt = (req->reply->tv.tv_sec - req->pack->tv.tv_sec) * 1000 + (req->reply->tv.tv_nsec - req->pack->tv.tv_nsec) / 1000000; stat_accm_add(req->serv->stat_acct_query_1m, dt); @@ -224,7 +224,7 @@ static void rad_acct_start_recv(struct rad_req_t *req) triton_timer_del(&req->timeout); triton_md_unregister_handler(&req->hnd, 1); - + if (rpd->acct_interim_interval) { rad_packet_free(req->reply); req->reply = NULL; @@ -244,20 +244,20 @@ static void rad_acct_start_recv(struct rad_req_t *req) } rpd->acct_started = 1; - + ap_session_accounting_started(rpd->ses); } static void rad_acct_start_timeout(struct triton_timer_t *t) { struct rad_req_t *req = container_of(t, typeof(*req), timeout); - + rad_server_timeout(req->serv); __sync_add_and_fetch(&req->serv->stat_acct_lost, 1); stat_accm_add(req->serv->stat_acct_lost_1m, 1); stat_accm_add(req->serv->stat_acct_lost_5m, 1); - + if (req->before_send) req->pack->id++; @@ -281,7 +281,7 @@ int rad_acct_start(struct radius_pd_t *rpd) req->before_send = rad_acct_before_send; else if (req_set_RA(req, req->serv->secret)) goto out_err; - + req->recv = rad_acct_start_recv; req->timeout.expire = rad_acct_start_timeout; req->timeout.expire_tv.tv_sec = conf_timeout; @@ -290,7 +290,7 @@ int rad_acct_start(struct radius_pd_t *rpd) if (rad_req_send(req)) goto out_err; - + rpd->acct_req = req; return 0; @@ -305,22 +305,22 @@ static void rad_acct_stop_sent(struct rad_req_t *req, int res) if (res) { if (ap_shutdown) { struct radius_pd_t *rpd = req->rpd; - + rad_req_free(req); - + if (rpd) rpd->acct_req = NULL; } else if (req->rpd) rad_acct_stop_defer(req->rpd); - + return; } - + __sync_add_and_fetch(&req->serv->stat_acct_sent, 1); - + if (!req->hnd.tpd) triton_md_register_handler(req->rpd ? req->rpd->ses->ctrl->ctx : NULL, &req->hnd); - + triton_md_enable_handler(&req->hnd, MD_MODE_READ); if (req->timeout.tpd) @@ -332,7 +332,7 @@ static void rad_acct_stop_sent(struct rad_req_t *req, int res) static void rad_acct_stop_recv(struct rad_req_t *req) { struct radius_pd_t *rpd = req->rpd; - int dt = (req->reply->tv.tv_sec - req->pack->tv.tv_sec) * 1000 + + int dt = (req->reply->tv.tv_sec - req->pack->tv.tv_sec) * 1000 + (req->reply->tv.tv_nsec - req->pack->tv.tv_nsec) / 1000000; stat_accm_add(req->serv->stat_acct_query_1m, dt); @@ -360,7 +360,7 @@ static void rad_acct_stop_timeout(struct triton_timer_t *t) __sync_add_and_fetch(&req->serv->stat_acct_lost, 1); stat_accm_add(req->serv->stat_acct_lost_1m, 1); stat_accm_add(req->serv->stat_acct_lost_5m, 1); - + if (req->before_send) req->pack->id++; } @@ -388,7 +388,7 @@ static void start_deferred(struct rad_req_t *req) if (rad_req_read(&req->hnd)) return; } - + triton_timer_add(NULL, &req->timeout, 0); } @@ -416,7 +416,7 @@ int rad_acct_stop(struct radius_pd_t *rpd) if (rpd->acct_interim_timer.tpd) triton_timer_del(&rpd->acct_interim_timer); - if (req) { + if (req) { rad_server_req_cancel(req, 1); clock_gettime(CLOCK_MONOTONIC, &ts); @@ -426,7 +426,7 @@ int rad_acct_stop(struct radius_pd_t *rpd) req = rad_req_alloc(rpd, CODE_ACCOUNTING_REQUEST, rpd->ses->username); if (!req) return -1; - + if (rad_req_acct_fill(req)) { log_ppp_error("radius:acct: failed to fill accounting attributes\n"); rad_req_free(req); @@ -470,13 +470,13 @@ int rad_acct_stop(struct radius_pd_t *rpd) rad_packet_change_val(req->pack, NULL, "Acct-Status-Type", "Stop"); req_set_stat(req, rpd->ses); req_set_RA(req, req->serv->secret); - + req->recv = rad_acct_stop_recv; req->timeout.expire = rad_acct_start_timeout; req->timeout.expire_tv.tv_sec = conf_timeout; req->sent = rad_acct_stop_sent; req->log = conf_verbose ? log_ppp_info1 : NULL; - + if (rad_req_send(req)) { rad_acct_stop_defer(rpd); return -1; diff --git a/accel-pppd/radius/auth.c b/accel-pppd/radius/auth.c index 43dec233..fbc2fab5 100644 --- a/accel-pppd/radius/auth.c +++ b/accel-pppd/radius/auth.c @@ -22,7 +22,7 @@ static int decrypt_chap_mppe_keys(struct rad_req_t *req, struct rad_attr_t *attr uint8_t sha1[SHA_DIGEST_LENGTH]; uint8_t plain[32]; int i; - + if (attr->len != 32) { log_ppp_warn("radius: %s: incorrect attribute length (%i)\n", attr->attr->name, attr->len); return -1; @@ -37,7 +37,7 @@ static int decrypt_chap_mppe_keys(struct rad_req_t *req, struct rad_attr_t *attr for (i = 0; i < 16; i++) plain[i] ^= md5[i]; - + MD5_Init(&md5_ctx); MD5_Update(&md5_ctx, req->serv->secret, strlen(req->serv->secret)); MD5_Update(&md5_ctx, attr->val.octets, 16); @@ -45,7 +45,7 @@ static int decrypt_chap_mppe_keys(struct rad_req_t *req, struct rad_attr_t *attr for (i = 0; i < 16; i++) plain[i + 16] ^= md5[i]; - + SHA1_Init(&sha1_ctx); SHA1_Update(&sha1_ctx, plain + 8, 16); SHA1_Update(&sha1_ctx, plain + 8, 16); @@ -63,7 +63,7 @@ static int decrypt_mppe_key(struct rad_req_t *req, struct rad_attr_t *attr, uint uint8_t md5[16]; uint8_t plain[32]; int i; - + if (attr->len != 34) { log_ppp_warn("radius: %s: incorrect attribute length (%i)\n", attr->attr->name, attr->len); return -1; @@ -84,7 +84,7 @@ static int decrypt_mppe_key(struct rad_req_t *req, struct rad_attr_t *attr, uint for (i = 0; i < 16; i++) plain[i] ^= md5[i]; - + if (plain[0] != 16) { log_ppp_warn("radius: %s: incorrect key length (%i)\n", attr->attr->name, plain[0]); return -1; @@ -116,7 +116,7 @@ static uint8_t* encrypt_password(const char *passwd, const char *secret, const u *epasswd_len = 0; return (uint8_t *)1; } - + epasswd = _malloc(chunk_cnt * 16); if (!epasswd) { log_emerg("radius: out of memory\n"); @@ -132,7 +132,7 @@ static uint8_t* encrypt_password(const char *passwd, const char *secret, const u MD5_Update(&ctx, secret, strlen(secret)); MD5_Update(&ctx, c, 16); MD5_Final(b, &ctx); - + for(j = 0; j < 16; j++) epasswd[i * 16 + j] ^= b[j]; @@ -164,17 +164,17 @@ static void rad_auth_recv(struct rad_req_t *req) unsigned int dt; triton_timer_del(&req->timeout); - + dt = (req->reply->tv.tv_sec - req->pack->tv.tv_sec) * 1000 + (req->reply->tv.tv_nsec - req->pack->tv.tv_nsec) / 1000000; stat_accm_add(req->serv->stat_auth_query_1m, dt); stat_accm_add(req->serv->stat_auth_query_5m, dt); - + if (pack->code == CODE_ACCESS_ACCEPT) { if (rad_proc_attrs(req)) { rad_auth_finalize(req->rpd, PWDB_DENIED); return; } - + struct ev_radius_t ev = { .ses = req->rpd->ses, .request = req->pack, @@ -185,14 +185,14 @@ static void rad_auth_recv(struct rad_req_t *req) rad_auth_finalize(req->rpd, PWDB_DENIED); return; } - + if (req->rpd->auth_ctx->recv && req->rpd->auth_ctx->recv(req)) { rad_auth_finalize(req->rpd, PWDB_DENIED); return; } - + req->rpd->authenticated = 1; - + rad_auth_finalize(req->rpd, PWDB_SUCCESS); } @@ -201,7 +201,7 @@ static void rad_auth_timeout(struct triton_timer_t *t) struct rad_req_t *req = container_of(t, typeof(*req), timeout); rad_server_timeout(req->serv); - + __sync_add_and_fetch(&req->serv->stat_auth_lost, 1); stat_accm_add(req->serv->stat_auth_lost_1m, 1); stat_accm_add(req->serv->stat_auth_lost_5m, 1); @@ -216,14 +216,14 @@ static void rad_auth_sent(struct rad_req_t *req, int res) rad_auth_finalize(req->rpd, PWDB_DENIED); return; } - + __sync_add_and_fetch(&req->serv->stat_auth_sent, 1); - + if (!req->hnd.tpd) triton_md_register_handler(req->rpd->ses->ctrl->ctx, &req->hnd); - + triton_md_enable_handler(&req->hnd, MD_MODE_READ); - + if (req->timeout.tpd) triton_timer_mod(&req->timeout, 0); else @@ -233,10 +233,10 @@ static void rad_auth_sent(struct rad_req_t *req, int res) static struct rad_req_t *rad_auth_req_alloc(struct radius_pd_t *rpd, const char *username, int (*recv)(struct rad_req_t *)) { struct rad_req_t *req = rad_req_alloc(rpd, CODE_ACCESS_REQUEST, username); - + if (!req) return NULL; - + if (conf_sid_in_auth) { if (rad_packet_add_str(req->pack, NULL, "Acct-Session-Id", rpd->ses->sessionid)) goto out; @@ -275,7 +275,7 @@ int rad_auth_pap(struct radius_pd_t *rpd, const char *username, va_list args) if (!req) return PWDB_DENIED; - + epasswd = encrypt_password(passwd, req->serv->secret, req->RA, &epasswd_len); if (!epasswd) return PWDB_DENIED; @@ -283,7 +283,7 @@ int rad_auth_pap(struct radius_pd_t *rpd, const char *username, va_list args) r = rad_packet_add_octets(req->pack, NULL, "User-Password", epasswd, epasswd_len); if (epasswd_len) _free(epasswd); - + if (r) return PWDB_DENIED; @@ -301,7 +301,7 @@ int rad_auth_chap_md5(struct radius_pd_t *rpd, const char *username, va_list arg uint8_t *challenge = va_arg(args, uint8_t *); int challenge_len = va_arg(args, int); uint8_t *response = va_arg(args, uint8_t *); - + if (!req) return PWDB_DENIED; @@ -316,7 +316,7 @@ int rad_auth_chap_md5(struct radius_pd_t *rpd, const char *username, va_list arg if (rad_packet_add_octets(req->pack, NULL, "CHAP-Password", chap_password, 17)) return PWDB_DENIED; - + if (rad_req_send(req)) return PWDB_DENIED; @@ -410,10 +410,10 @@ int rad_auth_mschap_v1(struct radius_pd_t *rpd, const char *username, va_list ar if (rad_packet_add_octets(req->pack, "Microsoft", "MS-CHAP-Challenge", challenge, challenge_len)) return PWDB_DENIED; - + if (rad_packet_add_octets(req->pack, "Microsoft", "MS-CHAP-Response", response, sizeof(response))) return PWDB_DENIED; - + if (rad_req_send(req)) return PWDB_DENIED; @@ -481,10 +481,10 @@ int rad_auth_mschap_v2(struct radius_pd_t *rpd, const char *username, va_list ar if (rad_packet_add_octets(req->pack, "Microsoft", "MS-CHAP-Challenge", challenge, 16)) return PWDB_DENIED; - + if (rad_packet_add_octets(req->pack, "Microsoft", "MS-CHAP2-Response", mschap_response, sizeof(mschap_response))) return PWDB_DENIED; - + if (rad_req_send(req)) return PWDB_DENIED; @@ -494,7 +494,7 @@ int rad_auth_mschap_v2(struct radius_pd_t *rpd, const char *username, va_list ar int rad_auth_null(struct radius_pd_t *rpd, const char *username, va_list args) { struct rad_req_t *req = rad_auth_req_alloc(rpd, username, NULL); - + if (!req) return PWDB_DENIED; diff --git a/accel-pppd/radius/backup.c b/accel-pppd/radius/backup.c index a44a7606..93ab3eb0 100644 --- a/accel-pppd/radius/backup.c +++ b/accel-pppd/radius/backup.c @@ -40,29 +40,29 @@ static int session_save(struct ap_session *ses, struct backup_mod *m) return -2; add_tag(RAD_TAG_INTERIM_INTERVAL, &rpd->acct_interim_interval, 4); - + if (rpd->session_timeout.tpd) add_tag(RAD_TAG_SESSION_TIMEOUT, &session_timeout, 8); - + if (rpd->idle_timeout.tpd) add_tag(RAD_TAG_IDLE_TIMEOUT, &idle_timeout, 4); - + if (ses->ipv4 == &rpd->ipv4_addr) add_tag(RAD_TAG_IPV4_ADDR, NULL, 0); - + if (ses->ipv6 == &rpd->ipv6_addr) add_tag(RAD_TAG_IPV6_ADDR, NULL, 0); - + /*if (rpd->ipv6_pd_assigned) { }*/ if (rpd->attr_class) add_tag(RAD_TAG_ATTR_CLASS, rpd->attr_class, rpd->attr_class_len); - + if (rpd->attr_state) add_tag(RAD_TAG_ATTR_CLASS, rpd->attr_state, rpd->attr_state_len); - + add_tag(RAD_TAG_TERMINATION_ACTION, &rpd->termination_action, 4); if (rpd->acct_req) { @@ -109,7 +109,7 @@ void radius_restore_session(struct ap_session *ses, struct radius_pd_t *rpd) if (!m) return; - + list_for_each_entry(tag, &m->tag_list, entry) { switch (tag->id) { case RAD_TAG_INTERIM_INTERVAL: @@ -149,10 +149,10 @@ void radius_restore_session(struct ap_session *ses, struct radius_pd_t *rpd) break; } } - + if (acct_addr) rpd->acct_req = rad_req_alloc2(rpd, CODE_ACCOUNTING_REQUEST, rpd->ses->username, acct_addr, acct_port); - + rpd->authenticated = 1; } diff --git a/accel-pppd/radius/dict.c b/accel-pppd/radius/dict.c index 32af3445..7f4849cd 100644 --- a/accel-pppd/radius/dict.c +++ b/accel-pppd/radius/dict.c @@ -15,7 +15,7 @@ static struct rad_dict_t *dict; static char *skip_word(char *ptr) { for(; *ptr; ptr++) - if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') + if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') break; return ptr; } @@ -34,9 +34,9 @@ static int split(char *buf, char **ptr) buf = skip_word(buf); if (!*buf) return i; - + *buf = 0; - + buf = skip_space(buf + 1); if (!*buf) return i; @@ -82,7 +82,7 @@ static int dict_load(const char *fname) log_emerg("radius: open dictioanary '%s': %s\n", fname, strerror(errno)); return -1; } - + items = &dict->items; while (fgets(buf, BUF_SIZE, f)) { @@ -301,7 +301,7 @@ __export struct rad_dict_attr_t *rad_dict_find_attr_id(struct rad_dict_vendor_t { struct rad_dict_attr_t *attr; struct list_head *items = vendor ? &vendor->items : &dict->items; - + list_for_each_entry(attr, items, entry) if (attr->id == id) return attr; diff --git a/accel-pppd/radius/dm_coa.c b/accel-pppd/radius/dm_coa.c index 0235ba4a..fd59bf11 100644 --- a/accel-pppd/radius/dm_coa.c +++ b/accel-pppd/radius/dm_coa.c @@ -36,7 +36,7 @@ static int dm_coa_check_RA(struct rad_packet_t *pack, const char *secret) MD5_CTX ctx; memset(RA, 0, 16); - + MD5_Init(&ctx); MD5_Update(&ctx, pack->buf, 4); MD5_Update(&ctx, RA, 16); @@ -69,7 +69,7 @@ static int dm_coa_send_ack(int fd, struct rad_packet_t *req, struct sockaddr_in return -1; reply->id = req->id; - + if (rad_packet_build(reply, RA)) { rad_packet_free(reply); return -1; @@ -83,7 +83,7 @@ static int dm_coa_send_ack(int fd, struct rad_packet_t *req, struct sockaddr_in } rad_packet_send(reply, fd, addr); - + rad_packet_free(reply); return 0; @@ -118,7 +118,7 @@ static int dm_coa_send_nak(int fd, struct rad_packet_t *req, struct sockaddr_in } rad_packet_send(reply, fd, addr); - + rad_packet_free(reply); return 0; @@ -135,7 +135,7 @@ static void disconnect_request(struct radius_pd_t *rpd) dm_coa_send_ack(serv.hnd.fd, rpd->dm_coa_req, &rpd->dm_coa_addr); rad_packet_free(rpd->dm_coa_req); - + pthread_mutex_lock(&rpd->lock); rpd->dm_coa_req = NULL; pthread_mutex_unlock(&rpd->lock); @@ -183,7 +183,7 @@ static void coa_request(struct radius_pd_t *rpd) dm_coa_send_ack(serv.hnd.fd, rpd->dm_coa_req, &rpd->dm_coa_addr); } - + rad_packet_free(rpd->dm_coa_req); pthread_mutex_lock(&rpd->lock); @@ -232,14 +232,14 @@ static int dm_coa_read(struct triton_md_handler_t *h) err_code = 403; goto out_err; } - + rpd = rad_find_session_pack(pack); if (!rpd) { log_warn("radius:dm_coa: session not found\n"); err_code = 503; goto out_err; } - + if (rpd->dm_coa_req) { pthread_mutex_unlock(&rpd->lock); goto out_err_no_reply; @@ -292,7 +292,7 @@ static void init(void) log_emerg("radius:dm_coa: socket: %s\n", strerror(errno)); return; } - + fcntl(serv.hnd.fd, F_SETFD, fcntl(serv.hnd.fd, F_GETFD) | FD_CLOEXEC); addr.sin_family = AF_INET; @@ -312,7 +312,7 @@ static void init(void) close(serv.hnd.fd); return; } - + triton_context_register(&serv.ctx, NULL); triton_md_register_handler(&serv.ctx, &serv.hnd); triton_md_enable_handler(&serv.hnd, MD_MODE_READ); diff --git a/accel-pppd/radius/packet.c b/accel-pppd/radius/packet.c index 87c337fe..92e43e2b 100644 --- a/accel-pppd/radius/packet.c +++ b/accel-pppd/radius/packet.c @@ -61,7 +61,7 @@ int rad_packet_build(struct rad_packet_t *pack, uint8_t *RA) log_emerg("radius:packet: out of memory\n"); return -1; } - + pack->buf = ptr; } else ptr = pack->buf; @@ -76,7 +76,7 @@ int rad_packet_build(struct rad_packet_t *pack, uint8_t *RA) *ptr = 26; ptr++; *ptr = attr->len + 2 + 6; ptr++; *(uint32_t *)ptr = htonl(attr->vendor->id); ptr+=4; - } + } *ptr = attr->attr->id; ptr++; *ptr = attr->len + 2; ptr++; switch(attr->attr->type) { @@ -133,7 +133,7 @@ int rad_packet_recv(int fd, struct rad_packet_t **p, struct sockaddr_in *addr) log_emerg("radius:packet: out of memory\n"); goto out_err; } - + pack->buf = ptr; clock_gettime(CLOCK_MONOTONIC, &pack->tv); @@ -225,7 +225,7 @@ int rad_packet_recv(int fd, struct rad_packet_t **p, struct sockaddr_in *addr) goto out_err; } memcpy(attr->val.octets, ptr, len); - break; + break; case ATTR_TYPE_DATE: case ATTR_TYPE_INTEGER: attr->val.integer = ntohl(*(uint32_t*)ptr); @@ -260,7 +260,7 @@ out_err: void rad_packet_free(struct rad_packet_t *pack) { struct rad_attr_t *attr; - + if (pack->buf) mempool_free(pack->buf); //munmap(pack->buf, REQ_LENGTH_MAX); @@ -286,7 +286,7 @@ void rad_packet_print(struct rad_packet_t *pack, struct rad_server_t *s, void (* uint16_t u16[4]; } ifid_u; in_addr_t addr; - + if (s) print("[RADIUS(%i) ", s->id); else @@ -392,7 +392,7 @@ int __export rad_packet_add_int(struct rad_packet_t *pack, const char *vendor_na if (!attr) return -1; - + ra = mempool_alloc(attr_pool); if (!ra) return -1; @@ -411,7 +411,7 @@ int __export rad_packet_add_int(struct rad_packet_t *pack, const char *vendor_na int __export rad_packet_change_int(struct rad_packet_t *pack, const char *vendor_name, const char *name, int val) { struct rad_attr_t *ra; - + ra = rad_packet_find_attr(pack, vendor_name, name); if (!ra) return -1; @@ -439,10 +439,10 @@ int __export rad_packet_add_octets(struct rad_packet_t *pack, const char *vendor vendor = NULL; attr = rad_dict_find_attr(name); } - + if (!attr) return -1; - + ra = mempool_alloc(attr_pool); if (!ra) { log_emerg("radius: out of memory\n"); @@ -473,7 +473,7 @@ int __export rad_packet_add_octets(struct rad_packet_t *pack, const char *vendor int __export rad_packet_change_octets(struct rad_packet_t *pack, const char *vendor_name, const char *name, const uint8_t *val, int len) { struct rad_attr_t *ra; - + ra = rad_packet_find_attr(pack, vendor_name, name); if (!ra) return -1; @@ -487,7 +487,7 @@ int __export rad_packet_change_octets(struct rad_packet_t *pack, const char *ven log_emerg("radius: out of memory\n"); return -1; } - + pack->len += len - ra->len; ra->len = len; } @@ -521,7 +521,7 @@ int __export rad_packet_add_str(struct rad_packet_t *pack, const char *vendor_na if (!attr) return -1; - + ra = mempool_alloc(attr_pool); if (!ra) { log_emerg("radius: out of memory\n"); @@ -549,7 +549,7 @@ int __export rad_packet_add_str(struct rad_packet_t *pack, const char *vendor_na int __export rad_packet_change_str(struct rad_packet_t *pack, const char *vendor_name, const char *name, const char *val, int len) { struct rad_attr_t *ra; - + ra = rad_packet_find_attr(pack, vendor_name, name); if (!ra) return -1; @@ -563,7 +563,7 @@ int __export rad_packet_change_str(struct rad_packet_t *pack, const char *vendor log_emerg("radius: out of memory\n"); return -1; } - + pack->len += len - ra->len; ra->len = len; } @@ -593,14 +593,14 @@ int __export rad_packet_add_val(struct rad_packet_t *pack, const char *vendor_na vendor = NULL; attr = rad_dict_find_attr(name); } - + if (!attr) return -1; v = rad_dict_find_val_name(attr, val); if (!v) return -1; - + ra = mempool_alloc(attr_pool); if (!ra) return -1; @@ -620,7 +620,7 @@ int __export rad_packet_change_val(struct rad_packet_t *pack, const char *vendor { struct rad_attr_t *ra; struct rad_dict_value_t *v; - + ra = rad_packet_find_attr(pack, vendor_name, name); if (!ra) return -1; @@ -630,7 +630,7 @@ int __export rad_packet_change_val(struct rad_packet_t *pack, const char *vendor return -1; ra->val = v->val; - + return 0; } @@ -660,7 +660,7 @@ int rad_packet_add_ifid(struct rad_packet_t *pack, const char *vendor_name, cons if (!attr) return -1; - + ra = mempool_alloc(attr_pool); if (!ra) return -1; @@ -697,7 +697,7 @@ int rad_packet_add_ipv6prefix(struct rad_packet_t *pack, const char *vendor_name if (!attr) return -1; - + ra = mempool_alloc(attr_pool); if (!ra) return -1; @@ -726,14 +726,14 @@ struct rad_attr_t __export *rad_packet_find_attr(struct rad_packet_t *pack, cons return NULL; } else vendor = NULL; - + list_for_each_entry(ra, &pack->attrs, entry) { if (vendor && vendor != ra->vendor) continue; if (strcmp(ra->attr->name, name)) continue; - + return ra; } diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c index 02df42f5..83d6d07d 100644 --- a/accel-pppd/radius/radius.c +++ b/accel-pppd/radius/radius.c @@ -126,10 +126,10 @@ int rad_proc_attrs(struct rad_req_t *req) else if (rpd->attr_state_len != attr->len) rpd->attr_state = _realloc(rpd->attr_state, attr->len); memcpy(rpd->attr_state, attr->val.octets, attr->len); - rpd->attr_state_len = attr->len; + rpd->attr_state_len = attr->len; break; case Termination_Action: - rpd->termination_action = attr->val.integer; + rpd->termination_action = attr->val.integer; break; case Framed_Interface_Id: rpd->ipv6_addr.peer_intf_id = attr->val.ifid; @@ -157,7 +157,7 @@ int rad_proc_attrs(struct rad_req_t *req) if (wins.ses) triton_event_fire(EV_WINS, &wins); - + if (!rpd->ses->ipv6_dp && !list_empty(&rpd->ipv6_dp.prefix_list)) rpd->ses->ipv6_dp = &rpd->ipv6_dp; @@ -178,14 +178,14 @@ static int rad_pwdb_check(struct pwdb_t *pwdb, struct ap_session *ses, pwdb_call log_ppp_error("radius: username is too large to append realm\n"); return PWDB_DENIED; } - + memcpy(username1, username, len); username1[len] = '@'; memcpy(username1 + len + 1, conf_default_realm, conf_default_realm_len); username1[len + 1 + conf_default_realm_len] = 0; username = username1; } - + rpd->auth_ctx = mempool_alloc(auth_ctx_pool); memset(rpd->auth_ctx, 0, sizeof(*rpd->auth_ctx)); @@ -232,7 +232,7 @@ static int rad_pwdb_check(struct pwdb_t *pwdb, struct ap_session *ses, pwdb_call static struct ipv4db_item_t *get_ipv4(struct ap_session *ses) { struct radius_pd_t *rpd = find_pd(ses); - + if (rpd->ipv4_addr.peer_addr) return &rpd->ipv4_addr; return NULL; @@ -305,7 +305,7 @@ static void ses_starting(struct ap_session *ses) INIT_LIST_HEAD(&rpd->plugin_list); INIT_LIST_HEAD(&rpd->ipv6_addr.addr_list); INIT_LIST_HEAD(&rpd->ipv6_dp.prefix_list); - + rpd->ipv4_addr.owner = &ipdb; rpd->ipv6_addr.owner = &ipdb; rpd->ipv6_dp.owner = &ipdb; @@ -325,10 +325,10 @@ static void ses_starting(struct ap_session *ses) static void ses_acct_start(struct ap_session *ses) { struct radius_pd_t *rpd = find_pd(ses); - + if (!conf_accounting) return; - + if (!rpd->authenticated) return; @@ -402,13 +402,13 @@ static void ses_finished(struct ap_session *ses) if (rpd->session_timeout.tpd) triton_timer_del(&rpd->session_timeout); - + if (rpd->idle_timeout.tpd) triton_timer_del(&rpd->idle_timeout); if (rpd->attr_class) _free(rpd->attr_class); - + if (rpd->attr_state) _free(rpd->attr_state); @@ -425,7 +425,7 @@ static void ses_finished(struct ap_session *ses) } list_del(&rpd->pd.entry); - + release_pd(rpd); } @@ -458,7 +458,7 @@ void release_pd(struct radius_pd_t *rpd) struct radius_pd_t *rad_find_session(const char *sessionid, const char *username, const char *port_id, int port, in_addr_t ipaddr, const char *csid) { struct radius_pd_t *rpd; - + pthread_rwlock_rdlock(&sessions_lock); list_for_each_entry(rpd, &sessions, entry) { if (!rpd->ses->username) @@ -492,7 +492,7 @@ struct radius_pd_t *rad_find_session_pack(struct rad_packet_t *pack) int port = -1; const char *port_id = NULL; in_addr_t ipaddr = 0; - + list_for_each_entry(attr, &pack->attrs, entry) { if (attr->vendor) continue; @@ -523,7 +523,7 @@ struct radius_pd_t *rad_find_session_pack(struct rad_packet_t *pack) if (username && !sessionid && port == -1 && ipaddr == 0 && !port_id) return NULL; - + return rad_find_session(sessionid, username, port_id, port, ipaddr, csid); } @@ -532,7 +532,7 @@ int rad_check_nas_pack(struct rad_packet_t *pack) struct rad_attr_t *attr; const char *ident = NULL; in_addr_t ipaddr = 0; - + list_for_each_entry(attr, &pack->attrs, entry) { if (!strcmp(attr->attr->name, "NAS-Identifier")) ident = attr->val.string; @@ -548,7 +548,7 @@ int rad_check_nas_pack(struct rad_packet_t *pack) if (conf_nas_ip_address && ipaddr && conf_nas_ip_address != ipaddr) return -1; - + return 0; } @@ -586,9 +586,9 @@ static int parse_server(const char *opt, in_addr_t *addr, int *port, char **secr *p2 = 0; else return -1; - + *addr = inet_addr(str); - + if (p1) { *port = atoi(p1 + 1); if (*port <=0 ) @@ -600,7 +600,7 @@ static int parse_server(const char *opt, in_addr_t *addr, int *port, char **secr *secret = p1; if (p2) _free(p2); - + _free(str); return 0; @@ -613,7 +613,7 @@ static int load_config(void) opt = conf_get_opt("radius", "max-try"); if (opt && atoi(opt) > 0) conf_max_try = atoi(opt); - + opt = conf_get_opt("radius", "timeout"); if (opt && atoi(opt) > 0) conf_timeout = atoi(opt); @@ -633,7 +633,7 @@ static int load_config(void) opt = conf_get_opt("radius", "nas-ip-address"); if (opt) conf_nas_ip_address = inet_addr(opt); - + if (conf_nas_identifier) _free(conf_nas_identifier); opt = conf_get_opt("radius", "nas-identifier"); @@ -641,7 +641,7 @@ static int load_config(void) conf_nas_identifier = _strdup(opt); else conf_nas_identifier = NULL; - + opt = conf_get_opt("radius", "gw-ip-address"); if (opt) conf_gw_ip_address = inet_addr(opt); @@ -661,11 +661,11 @@ static int load_config(void) opt = conf_get_opt("radius", "sid_in_auth"); if (opt) conf_sid_in_auth = atoi(opt); - + opt = conf_get_opt("radius", "require-nas-identification"); if (opt) conf_require_nas_ident = atoi(opt); - + opt = conf_get_opt("radius", "acct-interim-interval"); if (opt && atoi(opt) > 0) conf_acct_interim_interval = atoi(opt); @@ -675,7 +675,7 @@ static int load_config(void) conf_acct_delay_time = atoi(opt); conf_attr_tunnel_type = conf_get_opt("radius", "attr-tunnel-type"); - + conf_default_realm = conf_get_opt("radius", "default-realm"); if (conf_default_realm) conf_default_realm_len = strlen(conf_default_realm); @@ -695,7 +695,7 @@ static void radius_init(void) if (load_config()) _exit(EXIT_FAILURE); - + list_for_each_entry(opt1, &s->items, entry) { if (strcmp(opt1->name, "dictionary") || !opt1->val) continue; diff --git a/accel-pppd/radius/radius_p.h b/accel-pppd/radius/radius_p.h index 6f1be672..9687f820 100644 --- a/accel-pppd/radius/radius_p.h +++ b/accel-pppd/radius/radius_p.h @@ -70,9 +70,9 @@ struct rad_req_t { struct radius_pd_t *rpd; struct rad_server_t *serv; - + in_addr_t server_addr; - + int server_port; int type:8; int try:6; @@ -214,7 +214,7 @@ int rad_server_realloc(struct rad_req_t *); void rad_server_fail(struct rad_server_t *); void rad_server_timeout(struct rad_server_t *); void rad_server_reply(struct rad_server_t *); - + void radius_restore_session(struct ap_session *ses, struct radius_pd_t *rpd); struct rtnl_link_stats; diff --git a/accel-pppd/radius/req.c b/accel-pppd/radius/req.c index 129116b7..a2cf6a77 100644 --- a/accel-pppd/radius/req.c +++ b/accel-pppd/radius/req.c @@ -50,7 +50,7 @@ static struct rad_req_t *__rad_req_alloc(struct radius_pd_t *rpd, int code, cons if (!req->serv) goto out_err; - + req->server_addr = req->serv->addr; req->server_port = req->serv->auth_port; @@ -73,7 +73,7 @@ static struct rad_req_t *__rad_req_alloc(struct radius_pd_t *rpd, int code, cons if (rad_packet_add_str(req->pack, NULL, "User-Name", username)) goto out_err; - + if (conf_nas_identifier) if (rad_packet_add_str(req->pack, NULL, "NAS-Identifier", conf_nas_identifier)) goto out_err; @@ -84,10 +84,10 @@ static struct rad_req_t *__rad_req_alloc(struct radius_pd_t *rpd, int code, cons if (rad_packet_add_int(req->pack, NULL, "NAS-Port", rpd->ses->unit_idx)) goto out_err; - + if (rad_packet_add_str(req->pack, NULL, "NAS-Port-Id", rpd->ses->ifname)) goto out_err; - + if (req->rpd->ses->ctrl->type == CTRL_TYPE_IPOE) { if (rad_packet_add_val(req->pack, NULL, "NAS-Port-Type", "Ethernet")) goto out_err; @@ -105,15 +105,15 @@ static struct rad_req_t *__rad_req_alloc(struct radius_pd_t *rpd, int code, cons if (rpd->ses->ctrl->calling_station_id) if (rad_packet_add_str(req->pack, NULL, "Calling-Station-Id", rpd->ses->ctrl->calling_station_id)) goto out_err; - + if (rpd->ses->ctrl->called_station_id) if (rad_packet_add_str(req->pack, NULL, "Called-Station-Id", rpd->ses->ctrl->called_station_id)) goto out_err; - + if (rpd->attr_class) if (rad_packet_add_octets(req->pack, NULL, "Class", rpd->attr_class, rpd->attr_class_len)) goto out_err; - + if (conf_attr_tunnel_type) if (rad_packet_add_str(req->pack, NULL, conf_attr_tunnel_type, rpd->ses->ctrl->name)) goto out_err; @@ -240,7 +240,7 @@ void rad_req_free(struct rad_req_t *req) triton_md_unregister_handler(&req->hnd, 1); else if (req->hnd.fd != -1) close(req->hnd.fd); - + if (req->timeout.tpd) triton_timer_del(&req->timeout); @@ -288,7 +288,7 @@ static int make_socket(struct rad_req_t *req) log_ppp_error("radius: failed to set nonblocking mode: %s\n", strerror(errno)); goto out_err; } - + return 0; out_err: @@ -313,18 +313,18 @@ int __rad_req_send(struct rad_req_t *req, int async) if (req->hnd.fd == -1 && make_socket(req)) return -1; - + if (req->before_send && req->before_send(req)) goto out_err; if (!req->pack->buf && rad_packet_build(req->pack, req->RA)) goto out_err; - + if (req->log) { req->log("send "); rad_packet_print(req->pack, req->serv, req->log); } - + if (req->sent) req->sent(req, 0); @@ -339,7 +339,7 @@ out_err: close(req->hnd.fd); req->hnd.fd = -1; } - + if (async && req->sent) req->sent(req, -1); @@ -355,9 +355,9 @@ int rad_req_send(struct rad_req_t *req) if (req->try++ == conf_max_try) { if (req->active) rad_server_req_exit(req); - + log_ppp_warn("radius: server(%i) not responding\n", req->serv->id); - + if (rad_server_realloc(req)) { if (req->rpd) log_ppp_warn("radius: no available servers\n"); @@ -373,7 +373,7 @@ int rad_req_send(struct rad_req_t *req) if (r >= 0) break; - + if (rad_server_realloc(req)) { if (req->rpd) log_ppp_warn("radius: no available servers\n"); @@ -399,13 +399,13 @@ int rad_req_read(struct triton_md_handler_t *h) return 0; rad_server_reply(req->serv); - + if (pack->id == req->pack->id) break; - + rad_packet_free(pack); } - + req->reply = pack; if (req->active) diff --git a/accel-pppd/radius/serv.c b/accel-pppd/radius/serv.c index 718a3b2d..c66cc283 100644 --- a/accel-pppd/radius/serv.c +++ b/accel-pppd/radius/serv.c @@ -38,7 +38,7 @@ static struct rad_server_t *__rad_server_get(int type, struct rad_server_t *excl { struct rad_server_t *s, *s0 = NULL, *s1 = NULL; struct timespec ts; - + clock_gettime(CLOCK_MONOTONIC, &ts); list_for_each_entry(s, &serv_list, entry) { @@ -61,7 +61,7 @@ static struct rad_server_t *__rad_server_get(int type, struct rad_server_t *excl else if (!s1) s1 = s; } - + if (!s0) { s0 = s; continue; @@ -113,7 +113,7 @@ static void req_wakeup(struct rad_req_t *req) log_switch(triton_context_self(), NULL); log_ppp_debug("radius(%i): wakeup %p %i\n", req->serv->id, req, req->active); - + if (!req->active) return; @@ -126,13 +126,13 @@ static void req_wakeup(struct rad_req_t *req) req->serv->req_cnt--; log_ppp_debug("radius(%i): server failed\n", req->serv->id); pthread_mutex_unlock(&req->serv->lock); - + req->send(req, -1); return; } pthread_mutex_unlock(&req->serv->lock); - + req->send(req, 1); } @@ -166,7 +166,7 @@ int rad_server_req_cancel(struct rad_req_t *req, int full) if (req->timeout.tpd) triton_timer_del(&req->timeout); - + if (req->hnd.tpd) triton_md_unregister_handler(&req->hnd, 0); @@ -176,7 +176,7 @@ int rad_server_req_cancel(struct rad_req_t *req, int full) int rad_server_req_enter(struct rad_req_t *req) { struct timespec ts; - + if (req->serv->need_free || req->serv->starting) return -1; @@ -195,7 +195,7 @@ int rad_server_req_enter(struct rad_req_t *req) assert(!req->entry.next); pthread_mutex_lock(&req->serv->lock); - + if (ts.tv_sec < req->serv->fail_time) { pthread_mutex_unlock(&req->serv->lock); return -1; @@ -207,13 +207,13 @@ int rad_server_req_enter(struct rad_req_t *req) req->serv->queue_cnt++; log_ppp_debug("radius(%i): queue %p\n", req->serv->id, req); pthread_mutex_unlock(&req->serv->lock); - + if (req->hnd.tpd) triton_md_disable_handler(&req->hnd, MD_MODE_READ); return 0; } - + pthread_mutex_unlock(&req->serv->lock); return 1; } @@ -221,12 +221,12 @@ int rad_server_req_enter(struct rad_req_t *req) req->serv->req_cnt++; log_ppp_debug("radius(%i): req_enter %i\n", req->serv->id, req->serv->req_cnt); pthread_mutex_unlock(&req->serv->lock); - + req->active = 1; - + if (req->send) return req->send(req, 0); - + return 0; } @@ -289,7 +289,7 @@ void rad_server_fail(struct rad_server_t *s) { struct rad_req_t *r; struct timespec ts; - + clock_gettime(CLOCK_MONOTONIC, &ts); pthread_mutex_lock(&s->lock); @@ -329,7 +329,7 @@ void rad_server_reply(struct rad_server_t *s) static int req_set_RA(struct rad_req_t *req, const char *secret) { MD5_CTX ctx; - + if (rad_packet_build(req->pack, req->RA)) return -1; @@ -373,7 +373,7 @@ static void acct_on_timeout(struct triton_timer_t *t) rad_req_free(req); if (s->starting) s->starting = 0; - else + else __free_server(s); return; } @@ -384,7 +384,7 @@ static void acct_on_timeout(struct triton_timer_t *t) static void send_acct_on(struct rad_server_t *s) { struct rad_req_t *req = rad_req_alloc_empty(); - + log_switch(triton_context_self(), NULL); memset(req, 0, sizeof(*req)); @@ -406,10 +406,10 @@ static void send_acct_on(struct rad_server_t *s) req->pack = rad_packet_alloc(CODE_ACCOUNTING_REQUEST); if (!req->pack) goto out_err; - + if (rad_packet_add_val(req->pack, NULL, "Acct-Status-Type", s->starting ? "Accounting-On" : "Accounting-Off")) goto out_err; - + if (conf_nas_identifier) if (rad_packet_add_str(req->pack, NULL, "NAS-Identifier", conf_nas_identifier)) goto out_err; @@ -417,7 +417,7 @@ static void send_acct_on(struct rad_server_t *s) if (conf_nas_ip_address) if (rad_packet_add_ipaddr(req->pack, NULL, "NAS-IP-Address", conf_nas_ip_address)) goto out_err; - + if (req_set_RA(req, s->secret)) goto out_err; @@ -426,7 +426,7 @@ static void send_acct_on(struct rad_server_t *s) triton_timer_add(&s->ctx, &req->timeout, 0); return; - + out_err: rad_req_free(req); } @@ -434,12 +434,12 @@ out_err: static void serv_ctx_close(struct triton_context_t *ctx) { struct rad_server_t *s = container_of(ctx, typeof(*s), ctx); - + if (s->timer.tpd) triton_timer_del(&s->timer); s->need_close = 1; - + if (!s->client_cnt[0] && !s->client_cnt[1]) { if (s->acct_on) { s->acct_on = 0; @@ -467,7 +467,7 @@ static void show_stat(struct rad_server_t *s, void *client) cli_send(client, " state: active\r\n"); cli_sendv(client, " fail count: %lu\r\n", s->stat_fail_cnt); - + cli_sendv(client, " request count: %i\r\n", s->req_cnt); cli_sendv(client, " queue length: %i\r\n", s->queue_cnt); @@ -539,7 +539,7 @@ static void __add_server(struct rad_server_t *s) s->stat_interim_lost_5m = stat_accm_create(5 * 60); s->stat_interim_query_1m = stat_accm_create(60); s->stat_interim_query_5m = stat_accm_create(5 * 60); - + s->ctx.close = serv_ctx_close; triton_context_register(&s->ctx, NULL); @@ -587,9 +587,9 @@ static int parse_server_old(const char *opt, in_addr_t *addr, int *port, char ** *p2 = 0; else return -1; - + *addr = inet_addr(str); - + if (p1) { *port = atoi(p1 + 1); if (*port <=0 ) @@ -646,7 +646,7 @@ static void add_server_old(void) __add_server(s); return; } - + __add_server(s); if (acct_addr) { @@ -670,14 +670,14 @@ static int parse_server1(const char *_opt, struct rad_server_t *s) ptr1 = strchr(opt, ','); if (!ptr1) goto out; - + ptr2 = strchr(ptr1 + 1, ','); if (ptr2) ptr3 = strchr(ptr2 + 1, ','); else ptr3 = NULL; - + *ptr1 = 0; if (ptr2) *ptr2 = 0; @@ -694,7 +694,7 @@ static int parse_server1(const char *_opt, struct rad_server_t *s) } } else s->auth_port = 1812; - + if (ptr3) { if (ptr3[1]) { s->acct_port = strtol(ptr3 + 1, &endptr, 10); @@ -708,7 +708,7 @@ static int parse_server1(const char *_opt, struct rad_server_t *s) s->fail_timeout = conf_fail_timeout; s->req_limit = conf_req_limit; s->max_fail = conf_max_fail; - + return 0; out: @@ -725,7 +725,7 @@ static int parse_server2(const char *_opt, struct rad_server_t *s) ptr1 = strchr(opt, ','); if (!ptr1) goto out; - + ptr2 = strchr(ptr1 + 1, ','); *ptr1 = 0; @@ -770,7 +770,7 @@ static int parse_server2(const char *_opt, struct rad_server_t *s) } else s->fail_timeout = conf_fail_timeout; } - + ptr3 = strstr(ptr2, ",max-fail="); if (ptr3) { s->max_fail = strtol(ptr3 + 10, &endptr, 10); @@ -778,7 +778,7 @@ static int parse_server2(const char *_opt, struct rad_server_t *s) goto out; } else s->max_fail = conf_max_fail; - + ptr3 = strstr(ptr2, ",weight="); if (ptr3) { s->weight = atoi(ptr3 + 8); @@ -788,7 +788,7 @@ static int parse_server2(const char *_opt, struct rad_server_t *s) } } else s->weight = 1; - + ptr3 = strstr(ptr2, ",backup"); if (ptr3) s->backup = 1; @@ -799,7 +799,7 @@ static int parse_server2(const char *_opt, struct rad_server_t *s) *ptr2 = 0; s->secret = _strdup(ptr1 + 1); - + _free(opt); return 0; @@ -813,12 +813,12 @@ out: static void add_server(const char *opt) { struct rad_server_t *s = _malloc(sizeof(*s)); - + memset(s, 0, sizeof(*s)); if (!parse_server1(opt,s)) goto add; - + if (!parse_server2(opt,s)) goto add; @@ -841,13 +841,13 @@ static void load_config(void) list_for_each_entry(s, &serv_list, entry) s->need_free = 1; - + opt1 = conf_get_opt("radius", "acct-on"); if (opt1) conf_acct_on = atoi(opt1); else conf_acct_on = 0; - + opt1 = conf_get_opt("radius", "fail-timeout"); if (!opt1) opt1 = conf_get_opt("radius", "fail-time"); @@ -861,7 +861,7 @@ static void load_config(void) conf_req_limit = atoi(opt1); else conf_req_limit = 0; - + opt1 = conf_get_opt("radius", "max-fail"); if (opt1) conf_max_fail = atoi(opt1); @@ -873,7 +873,7 @@ static void load_config(void) continue; add_server(opt->val); } - + list_for_each_safe(pos, n, &serv_list) { s = list_entry(pos, typeof(*s), entry); if (s->need_free) { @@ -893,9 +893,9 @@ static void load_config(void) } } } - + add_server_old(); - + conf_accounting = 0; list_for_each_entry(s, &serv_list, entry) { if (s->acct_port) { @@ -903,7 +903,7 @@ static void load_config(void) break; } } - + list_for_each_entry(s, &serv_list, entry) { if (s->starting) { if (!conf_accounting || !s->auth_port) diff --git a/accel-pppd/radius/stat_accm.c b/accel-pppd/radius/stat_accm.c index 2388c5d3..fe5da6ed 100644 --- a/accel-pppd/radius/stat_accm.c +++ b/accel-pppd/radius/stat_accm.c @@ -52,7 +52,7 @@ static void stat_accm_clean(struct stat_accm_t *s) { struct item_t *it; struct timespec ts; - + clock_gettime(CLOCK_MONOTONIC, &ts); while (!list_empty(&s->items)) { @@ -71,11 +71,11 @@ void stat_accm_add(struct stat_accm_t *s, unsigned int val) { struct item_t *it; struct timespec ts; - + clock_gettime(CLOCK_MONOTONIC, &ts); pthread_mutex_lock(&s->lock); - + stat_accm_clean(s); it = mempool_alloc(item_pool); @@ -84,7 +84,7 @@ void stat_accm_add(struct stat_accm_t *s, unsigned int val) list_add_tail(&it->entry, &s->items); ++s->items_cnt; s->total += val; - + pthread_mutex_unlock(&s->lock); } @@ -104,7 +104,7 @@ unsigned long stat_accm_get_avg(struct stat_accm_t *s) stat_accm_clean(s); val = s->items_cnt ? s->total/s->items_cnt : 0; pthread_mutex_unlock(&s->lock); - + return val; } diff --git a/accel-pppd/session.c b/accel-pppd/session.c index 8885cb22..12e4fc2b 100644 --- a/accel-pppd/session.c +++ b/accel-pppd/session.c @@ -94,7 +94,7 @@ int __export ap_session_starting(struct ap_session *ses) } ses->ifindex = ifr.ifr_ifindex; } - + if (ses->ifindex != -1) ap_session_set_ifindex(ses); @@ -105,13 +105,13 @@ int __export ap_session_starting(struct ap_session *ses) ses->state = AP_STATE_STARTING; } - + __sync_add_and_fetch(&ap_session_stat.starting, 1); pthread_rwlock_wrlock(&ses_lock); list_add_tail(&ses->entry, &ses_list); pthread_rwlock_unlock(&ses_lock); - + triton_event_fire(EV_SES_STARTING, ses); return 0; @@ -185,12 +185,12 @@ void __export ap_session_finished(struct ap_session *ses) _free(ses->ipv4_pool_name); ses->ipv4_pool_name = NULL; } - + if (ses->ipv6_pool_name) { _free(ses->ipv6_pool_name); ses->ipv6_pool_name = NULL; } - + if (ses->ifname_rename) { _free(ses->ifname_rename); ses->ifname_rename = NULL; @@ -200,7 +200,7 @@ void __export ap_session_finished(struct ap_session *ses) if (ses->backup) ses->backup->storage->free(ses->backup); #endif - + if (ap_shutdown && !ap_session_stat.starting && !ap_session_stat.active && !ap_session_stat.finishing) { if (shutdown_cb) shutdown_cb(); @@ -225,7 +225,7 @@ void __export ap_session_terminate(struct ap_session *ses, int cause, int hard) ses->ctrl->terminate(ses, hard); return; } - + if (ses->state == AP_STATE_ACTIVE) __sync_sub_and_fetch(&ap_session_stat.active, 1); else @@ -271,7 +271,7 @@ static void generate_sessionid(struct ap_session *ses) #else sid = __sync_add_and_fetch(&seq, 1); #endif - + clock_gettime(CLOCK_MONOTONIC, &ts); if (ts.tv_sec - seq_ts.tv_sec > conf_seq_save_timeout) save_seq(); @@ -307,7 +307,7 @@ int __export ap_session_read_stats(struct ap_session *ses, struct rtnl_link_stat log_ppp_warn("failed to get interface statistics\n"); return -1; } - + stats->rx_packets -= ses->acct_rx_packets_i; stats->tx_packets -= ses->acct_tx_packets_i; stats->rx_bytes -= ses->acct_rx_bytes_i; @@ -367,7 +367,7 @@ static void save_seq(void) FILE *f; char path[PATH_MAX]; const char *ptr; - + if (conf_sid_source != SID_SOURCE_SEQ) return; @@ -397,16 +397,16 @@ static void load_config(void) else if (strcmp(opt, "lower")) log_emerg("sid-case: invalid format\n"); } - + opt = conf_get_opt("common", "single-session"); if (opt) { if (!strcmp(opt, "deny")) conf_single_session = 0; else if (!strcmp(opt, "replace")) conf_single_session = 1; - } else + } else conf_single_session = -1; - + opt = conf_get_opt("common", "sid-source"); if (opt) { if (strcmp(opt, "seq") == 0) @@ -417,7 +417,7 @@ static void load_config(void) log_error("unknown sid-source\n"); } else conf_sid_source = SID_SOURCE_SEQ; - + conf_seq_file = conf_get_opt("common", "seq-file"); if (!conf_seq_file) conf_seq_file = "/var/lib/accel-ppp/seq"; @@ -436,7 +436,7 @@ static void init(void) perror("socket"); _exit(EXIT_FAILURE); } - + fcntl(sock_fd, F_SETFD, fcntl(sock_fd, F_GETFD) | FD_CLOEXEC); sock6_fd = socket(AF_INET6, SOCK_DGRAM, 0); @@ -450,7 +450,7 @@ static void init(void) log_emerg("failed to open /dev/urandom: %s\n", strerror(errno)); return; } - + fcntl(urandom_fd, F_SETFD, fcntl(urandom_fd, F_GETFD) | FD_CLOEXEC); load_config(); diff --git a/accel-pppd/session_backup.c b/accel-pppd/session_backup.c index 86073623..dea5b600 100644 --- a/accel-pppd/session_backup.c +++ b/accel-pppd/session_backup.c @@ -52,7 +52,7 @@ static int session_save(struct ap_session *ses, struct backup_mod *m) //add_tag_int(PPP_TAG_UNIT, &ses->unit_idx, sizeof(ses->unit_idx)); //triton_event_fire(EV_PPP_SESSION_SAVE, &ev); - + return 0; } @@ -115,7 +115,7 @@ static int session_restore(struct ap_session *ses, struct backup_mod *m) break;*/ } } - + return 0; //return establish_ses(ses); } diff --git a/accel-pppd/shaper/leaf_qdisc.c b/accel-pppd/shaper/leaf_qdisc.c index a2628e0a..d6b29583 100644 --- a/accel-pppd/shaper/leaf_qdisc.c +++ b/accel-pppd/shaper/leaf_qdisc.c @@ -30,12 +30,12 @@ static int parse_size(const char *str, int *r) if (endptr == str) return -1; - + if (*endptr == 0) { *r = sz; return 0; } - + if (strcmp(endptr, "kb") == 0 || strcmp(endptr, "k") == 0) *r = sz * 1024; else if (strcmp(endptr, "mb") == 0 || strcmp(endptr, "m") == 0) @@ -66,12 +66,12 @@ static int parse_time(const char *str, int *r) if (endptr == str) return -1; - + if (*endptr == 0) { *r = t; return 0; } - + if (strcmp(endptr, "s") == 0 || strcmp(endptr, "sec") == 0) *r = t * TIME_UNITS_PER_SEC; else if (strcmp(endptr, "ms") == 0 || strcmp(endptr, "msec") == 0) @@ -109,17 +109,17 @@ static int parse_sfq(char *str) if (!*str) goto out; - + while (1) { for (ptr1 = str + 1; *ptr1 && *ptr1 != ' '; ptr1++); if (!*ptr1) return -1; - + *ptr1 = 0; for (ptr1++; *ptr1 && *ptr1 == ' '; ptr1++); - + if (!*ptr1) return -1; @@ -160,7 +160,7 @@ static int parse_fq_codel(char *str) char *ptr1, *ptr2; conf_lq_arg6 = -1; - + if (!*str) goto out; @@ -169,11 +169,11 @@ static int parse_fq_codel(char *str) if (!*ptr1) return -1; - + *ptr1 = 0; for (ptr1++; *ptr1 && *ptr1 == ' '; ptr1++); - + if (!*ptr1) return -1; @@ -241,9 +241,9 @@ void leaf_qdisc_parse(const char *opt) #endif } else log_emerg("shaper: unknown leaf-qdisc '%s'\n", str); - + free(str); - + return; out_err: log_emerg("shaper: failed to parse '%s'\n", opt); @@ -256,7 +256,7 @@ static int qdisc_sfq(struct qdisc_opt *qopt, struct nlmsghdr *n) .perturb_period = conf_lq_arg2, .limit = conf_lq_arg3, }; - + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); return 0; @@ -316,12 +316,12 @@ int install_leaf_qdisc(struct rtnl_handle *rth, int ifindex, int parent, int han { if (conf_leaf_qdisc == LEAF_QDISC_SFQ) return install_sfq(rth, ifindex, parent, handle); - + #ifdef TCA_FQ_CODEL_MAX else if (conf_leaf_qdisc == LEAF_QDISC_FQ_CODEL) return install_fq_codel(rth, ifindex, parent, handle); #endif - + return 0; } diff --git a/accel-pppd/shaper/limiter.c b/accel-pppd/shaper/limiter.c index 2398bfea..b0525cb8 100644 --- a/accel-pppd/shaper/limiter.c +++ b/accel-pppd/shaper/limiter.c @@ -59,7 +59,7 @@ static int qdisc_htb_root(struct qdisc_opt *qopt, struct nlmsghdr *n) opt.rate2quantum = qopt->quantum; opt.version = 3; opt.defcls = qopt->defcls; - + tail = NLMSG_TAIL(n); addattr_l(n, TCA_BUF_MAX, TCA_OPTIONS, NULL, 0); addattr_l(n, TCA_BUF_MAX, TCA_HTB_INIT, &opt, NLMSG_ALIGN(sizeof(opt))); @@ -131,9 +131,9 @@ int tc_qdisc_modify(struct rtnl_handle *rth, int ifindex, int cmd, unsigned flag if (opt->handle) req.t.tcm_handle = opt->handle; - + req.t.tcm_parent = opt->parent; - + if (opt->kind) addattr_l(&req.n, sizeof(req), TCA_KIND, opt->kind, strlen(opt->kind) + 1); @@ -171,7 +171,7 @@ static int install_htb(struct rtnl_handle *rth, int ifindex, int rate, int burst .defcls = 1, .qdisc = qdisc_htb_root, }; - + struct qdisc_opt opt2 = { .kind = "htb", .handle = 0x00010001, @@ -185,10 +185,10 @@ static int install_htb(struct rtnl_handle *rth, int ifindex, int rate, int burst if (tc_qdisc_modify(rth, ifindex, RTM_NEWQDISC, NLM_F_EXCL|NLM_F_CREATE, &opt1)) return -1; - + if (tc_qdisc_modify(rth, ifindex, RTM_NEWTCLASS, NLM_F_EXCL|NLM_F_CREATE, &opt2)) return -1; - + return 0; } @@ -211,7 +211,7 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu .handle = 0xffff0000, .parent = TC_H_INGRESS, }; - + struct sel { struct tc_u32_sel sel; struct tc_u32_key key; @@ -220,7 +220,7 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu .sel.flags = TC_U32_TERMINAL, .key.off = 12, }; - + struct tc_police police = { .action = TC_POLICE_SHOT, .rate.rate = rate, @@ -231,7 +231,7 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu if (tc_qdisc_modify(rth, ifindex, RTM_NEWQDISC, NLM_F_EXCL|NLM_F_CREATE, &opt1)) return -1; - + if (tc_calc_rtable(&police.rate, rtab, Rcell_log, mtu, linklayer) < 0) { log_ppp_error("shaper: failed to calculate ceil rate table.\n"); return -1; @@ -246,9 +246,9 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu req.t.tcm_ifindex = ifindex; req.t.tcm_handle = 1; req.t.tcm_parent = 0xffff0000; - + req.t.tcm_info = TC_H_MAKE(100 << 16, ntohs(ETH_P_IP)); - + addattr_l(&req.n, sizeof(req), TCA_KIND, "u32", 4); tail = NLMSG_TAIL(&req.n); @@ -266,15 +266,15 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu addattr_l(&req.n, MAX_MSG, TCA_POLICE_TBF, &police, sizeof(police)); addattr_l(&req.n, MAX_MSG, TCA_POLICE_RATE, rtab, 1024); tail3->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail3; - + tail2->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail2; - + tail1->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail1; addattr_l(&req.n, MAX_MSG, TCA_U32_CLASSID, &flowid, 4); addattr_l(&req.n, MAX_MSG, TCA_U32_SEL, &sel, sizeof(sel)); tail->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail; - + if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; @@ -300,13 +300,13 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, .quantum = conf_quantum, .qdisc = qdisc_htb_class, }; - + struct qdisc_opt opt2 = { .kind = "ingress", .handle = 0xffff0000, .parent = TC_H_INGRESS, }; - + struct sel { struct tc_u32_sel sel; struct tc_u32_key key; @@ -315,11 +315,11 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, .sel.flags = TC_U32_TERMINAL, .key.off = 0, }; - + struct tc_skbedit p1 = { .action = TC_ACT_PIPE, }; - + struct tc_mirred p2 = { .eaction = TCA_EGRESS_REDIR, .action = TC_ACT_STOLEN, @@ -328,10 +328,10 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, if (tc_qdisc_modify(rth, conf_ifb_ifindex, RTM_NEWTCLASS, NLM_F_EXCL|NLM_F_CREATE, &opt1)) return -1; - + if (tc_qdisc_modify(rth, ifindex, RTM_NEWQDISC, NLM_F_EXCL|NLM_F_CREATE, &opt2)) return -1; - + memset(&req, 0, sizeof(req)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)); @@ -341,10 +341,10 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, req.t.tcm_ifindex = ifindex; req.t.tcm_handle = 1; req.t.tcm_parent = 0xffff0000; - + req.t.tcm_info = TC_H_MAKE(100 << 16, ntohs(ETH_P_IP)); - + addattr_l(&req.n, sizeof(req), TCA_KIND, "u32", 4); tail = NLMSG_TAIL(&req.n); @@ -353,7 +353,7 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, tail1 = NLMSG_TAIL(&req.n); addattr_l(&req.n, MAX_MSG, TCA_U32_ACT, NULL, 0); - // action skbedit priority X pipe + // action skbedit priority X pipe tail2 = NLMSG_TAIL(&req.n); addattr_l(&req.n, MAX_MSG, 1, NULL, 0); addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, "skbedit", 8); @@ -363,9 +363,9 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, addattr_l(&req.n, MAX_MSG, TCA_SKBEDIT_PARMS, &p1, sizeof(p1)); addattr_l(&req.n, MAX_MSG, TCA_SKBEDIT_PRIORITY, &priority, sizeof(priority)); tail3->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail3; - + tail2->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail2; - + tail1->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail1; // action mirred egress redirect dev ifb0 @@ -377,16 +377,16 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, addattr_l(&req.n, MAX_MSG, TCA_ACT_OPTIONS, NULL, 0); addattr_l(&req.n, MAX_MSG, TCA_MIRRED_PARMS, &p2, sizeof(p2)); tail3->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail3; - + tail2->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail2; - + tail1->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail1; // addattr32(&req.n, TCA_BUF_MAX, TCA_U32_CLASSID, 1); addattr_l(&req.n, MAX_MSG, TCA_U32_SEL, &sel, sizeof(sel)); tail->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail; - + if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; @@ -410,14 +410,14 @@ static int install_fwmark(struct rtnl_handle *rth, int ifindex, int parent) req.n.nlmsg_type = RTM_NEWTFILTER; req.t.tcm_family = AF_UNSPEC; req.t.tcm_ifindex = ifindex; - req.t.tcm_handle = 1; + req.t.tcm_handle = conf_fwmark; req.t.tcm_parent = parent; req.t.tcm_info = TC_H_MAKE(90 << 16, ntohs(ETH_P_IP)); - + addattr_l(&req.n, sizeof(req), TCA_KIND, "fw", 3); tail = NLMSG_TAIL(&req.n); addattr_l(&req.n, TCA_BUF_MAX, TCA_OPTIONS, NULL, 0); - addattr32(&req.n, TCA_BUF_MAX, TCA_FW_CLASSID, TC_H_MAKE(conf_fwmark << 16, 0)); + addattr32(&req.n, TCA_BUF_MAX, TCA_FW_CLASSID, TC_H_MAKE(1 << 16, 0)); tail->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail; return rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0); } @@ -428,7 +428,7 @@ static int remove_root(struct rtnl_handle *rth, int ifindex) .handle = 0x00010000, .parent = TC_H_ROOT, }; - + return tc_qdisc_modify(rth, ifindex, RTM_DELQDISC, 0, &opt); } @@ -438,7 +438,7 @@ static int remove_ingress(struct rtnl_handle *rth, int ifindex) .handle = 0xffff0000, .parent = TC_H_INGRESS, }; - + return tc_qdisc_modify(rth, ifindex, RTM_DELQDISC, 0, &opt); } @@ -448,7 +448,7 @@ static int remove_htb_ifb(struct rtnl_handle *rth, int ifindex, int priority) .handle = 0x00010001 + priority, .parent = 0x00010000, }; - + return tc_qdisc_modify(rth, conf_ifb_ifindex, RTM_DELTCLASS, 0, &opt); } @@ -456,7 +456,7 @@ int install_limiter(struct ap_session *ses, int down_speed, int down_burst, int { struct rtnl_handle rth; int r; - + if (rtnl_open(&rth, 0)) { log_ppp_error("shaper: cannot open rtnetlink\n"); return -1; @@ -483,11 +483,9 @@ int install_limiter(struct ap_session *ses, int down_speed, int down_burst, int r = install_leaf_qdisc(&rth, conf_ifb_ifindex, 0x00010001 + ses->unit_idx + 1, (1 + ses->unit_idx + 1) << 16); } - if (conf_fwmark) { + if (conf_fwmark) install_fwmark(&rth, ses->ifindex, 0x00010000); - install_fwmark(&rth, ses->ifindex, TC_H_INGRESS); - } - + rtnl_close(&rth); return r; @@ -504,7 +502,7 @@ int remove_limiter(struct ap_session *ses) remove_root(&rth, ses->ifindex); remove_ingress(&rth, ses->ifindex); - + if (conf_up_limiter == LIM_HTB) remove_htb_ifb(&rth, ses->ifindex, ses->unit_idx + 1); @@ -525,7 +523,7 @@ int init_ifb(const char *name) struct tcmsg t; char buf[TCA_BUF_MAX]; } req; - + struct qdisc_opt opt = { .kind = "htb", .handle = 0x00010000, @@ -536,7 +534,7 @@ int init_ifb(const char *name) if (system("modprobe -q ifb")) log_warn("failed to load ifb kernel module\n"); - + memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, name); @@ -546,7 +544,7 @@ int init_ifb(const char *name) } conf_ifb_ifindex = ifr.ifr_ifindex; - + ifr.ifr_flags |= IFF_UP; if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr)) { @@ -575,7 +573,7 @@ int init_ifb(const char *name) req.t.tcm_handle = 1; req.t.tcm_parent = 0x00010000; req.t.tcm_info = TC_H_MAKE(100 << 16, ntohs(ETH_P_IP)); - + addattr_l(&req.n, sizeof(req), TCA_KIND, "flow", 5); tail = NLMSG_TAIL(&req.n); diff --git a/accel-pppd/shaper/shaper.c b/accel-pppd/shaper/shaper.c index fa89e62b..b1eaabee 100644 --- a/accel-pppd/shaper/shaper.c +++ b/accel-pppd/shaper/shaper.c @@ -155,7 +155,7 @@ static void parse_string(const char *str, int dir, int *speed, int *burst, int * } return; } - + str1 = strstr(str, "rate-limit output"); if (str1) { val = sscanf(str1, "rate-limit output %u %u %u", &n1, &n2, &n3); @@ -175,7 +175,7 @@ static void parse_string(const char *str, int dir, int *speed, int *burst, int * } return; } - + str1 = strstr(str, "rate-limit input"); if (str1) { val = sscanf(str1, "rate-limit input %u %u %u", &n1, &n2, &n3); @@ -183,8 +183,8 @@ static void parse_string(const char *str, int dir, int *speed, int *burst, int * *speed = n1/1000; *burst = n2; } + return; } - return; } val = strtol(str, &endptr, 10); @@ -212,7 +212,7 @@ static void parse_string(const char *str, int dir, int *speed, int *burst, int * static struct time_range_pd_t *get_tr_pd(struct shaper_pd_t *pd, int id) { struct time_range_pd_t *tr_pd; - + list_for_each_entry(tr_pd, &pd->tr_list, entry) { if (tr_pd->id == id) return tr_pd; @@ -224,7 +224,7 @@ static struct time_range_pd_t *get_tr_pd(struct shaper_pd_t *pd, int id) if (id == time_range_id || id == 0) pd->cur_tr = tr_pd; - + list_add_tail(&tr_pd->entry, &pd->tr_list); return tr_pd; @@ -304,13 +304,13 @@ static void ev_radius_coa(struct ev_radius_t *ev) ev->res = -1; return; } - + clear_tr_pd(pd); check_radius_attrs(pd, ev->request); - + if (pd->temp_down_speed || pd->temp_up_speed) return; - + if (!pd->cur_tr) { if (pd->down_speed || pd->up_speed) { pd->down_speed = 0; @@ -330,7 +330,7 @@ static void ev_radius_coa(struct ev_radius_t *ev) ev->res = -1; return; } - + if (pd->down_speed > 0 || pd->up_speed > 0) { if (install_limiter(ev->ses, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { ev->res= -1; @@ -396,10 +396,10 @@ static void ev_ppp_pre_up(struct ap_session *ses) int down_speed, down_burst; int up_speed, up_burst; struct shaper_pd_t *pd = find_pd(ses, 1); - + if (!pd) return; - + if (temp_down_speed || temp_up_speed) { pd->temp_down_speed = temp_down_speed; pd->temp_up_speed = temp_up_speed; @@ -476,7 +476,7 @@ static void shaper_change(struct shaper_pd_t *pd) pd->down_speed = 0; pd->up_speed = 0; } - + out: if (__sync_sub_and_fetch(&pd->refs, 1) == 0) { clear_tr_pd(pd); @@ -499,10 +499,10 @@ static int shaper_change_exec(const char *cmd, char * const *f, int f_cnt, void //if (down_speed == 0 || up_speed == 0) // return CLI_CMD_INVAL; - + if (!strcmp(f[2], "all")) all = 1; - + if (f_cnt == 5) { if (strcmp(f[4], "temp")) return CLI_CMD_SYNTAX; @@ -583,12 +583,12 @@ static int shaper_restore_exec(const char *cmd, char * const *f, int f_cnt, void if (f_cnt != 3) return CLI_CMD_SYNTAX; - + if (strcmp(f[2], "all")) all = 0; else all = 1; - + pthread_rwlock_rdlock(&shaper_lock); if (all) { temp_down_speed = 0; @@ -612,7 +612,7 @@ static int shaper_restore_exec(const char *cmd, char * const *f, int f_cnt, void if (!all && !found) cli_send(cli, "not found\r\n"); - + return CLI_CMD_OK; } @@ -665,7 +665,7 @@ static void update_shaper_tr(struct shaper_pd_t *pd) goto out; remove_limiter(pd->ses); } - + if (pd->cur_tr && (pd->cur_tr->down_speed || pd->cur_tr->up_speed)) { pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; @@ -707,7 +707,7 @@ static void time_range_end_timer(struct triton_timer_t *t) struct shaper_pd_t *pd; time_range_id = 0; - + log_debug("shaper: time_range_end_timer\n"); pthread_rwlock_rdlock(&shaper_lock); @@ -730,7 +730,7 @@ static struct time_range_t *parse_range(time_t t, const char *val) return NULL; if (id <= 0) return NULL; - + localtime_r(&t, &begin_tm); begin_tm.tm_sec = 0; end_tm = begin_tm; @@ -738,11 +738,11 @@ static struct time_range_t *parse_range(time_t t, const char *val) endptr = strptime(endptr + 1, "%H:%M", &begin_tm); if (*endptr != '-') return NULL; - + endptr = strptime(endptr + 1, "%H:%M", &end_tm); if (*endptr) return NULL; - + r = _malloc(sizeof(*r)); memset(r, 0, sizeof(*r)); @@ -766,7 +766,7 @@ static void load_time_ranges(void) if (!s) return; - + time(&ts); while (!list_empty(&time_range_list)) { @@ -813,7 +813,7 @@ static void load_time_ranges(void) r->end.expire_tv.tv_sec += 24 * 60 * 60; triton_timer_add(&shaper_ctx, &r->begin, 1); - + if (r->end.period) triton_timer_add(&shaper_ctx, &r->end, 1); } @@ -851,7 +851,7 @@ static int parse_vendor_opt(const char *opt) vendor = rad_dict_find_vendor_name(opt); if (vendor) return vendor->id; - + return atoi(opt); } #endif @@ -875,7 +875,7 @@ static void load_config(void) opt = conf_get_opt("shaper", "attr-down"); if (opt) conf_attr_down = parse_attr_opt(opt); - + opt = conf_get_opt("shaper", "attr-up"); if (opt) conf_attr_up = parse_attr_opt(opt); @@ -886,13 +886,13 @@ static void load_config(void) } } #endif - + opt = conf_get_opt("shaper", "burst-factor"); if (opt) { conf_down_burst_factor = strtod(opt, NULL); conf_up_burst_factor = conf_down_burst_factor * 10; } - + opt = conf_get_opt("shaper", "down-burst-factor"); if (opt) conf_down_burst_factor = strtod(opt, NULL); @@ -926,13 +926,13 @@ static void load_config(void) conf_quantum = atoi(opt); else conf_quantum = 0; - + opt = conf_get_opt("shaper", "moderate-quantum"); if (opt) conf_moderate_quantum = atoi(opt); else conf_moderate_quantum = 0; - + opt = conf_get_opt("shaper", "cburst"); if (opt && atoi(opt) >= 0) conf_cburst = atoi(opt); @@ -972,19 +972,19 @@ static void load_config(void) opt = conf_get_opt("shaper", "verbose"); if (opt && atoi(opt) >= 0) conf_verbose = atoi(opt) > 0; - + opt = conf_get_opt("shaper", "rate-multiplier"); if (opt && atof(opt) > 0) conf_multiplier = atof(opt); else conf_multiplier = 1; - + opt = conf_get_opt("shaper", "fwmark"); if (opt) - conf_fwmark = atof(opt); + conf_fwmark = atoi(opt); else conf_fwmark = 0; - + triton_context_call(&shaper_ctx, (triton_event_func)load_time_ranges, NULL); } @@ -993,7 +993,7 @@ static void init(void) const char *opt; tc_core_init(); - + opt = conf_get_opt("shaper", "ifb"); if (opt && init_ifb(opt)) _exit(0); diff --git a/accel-pppd/shaper/shaper.h b/accel-pppd/shaper/shaper.h index 4864b86f..87cf45fe 100644 --- a/accel-pppd/shaper/shaper.h +++ b/accel-pppd/shaper/shaper.h @@ -21,7 +21,7 @@ struct qdisc_opt { int quantum; int defcls; int (*qdisc)(struct qdisc_opt *opt, struct nlmsghdr *n); -}; +}; extern int conf_up_limiter; extern int conf_down_limiter; diff --git a/accel-pppd/triton/conf_file.c b/accel-pppd/triton/conf_file.c index 0ca481cb..ebde6af2 100644 --- a/accel-pppd/triton/conf_file.c +++ b/accel-pppd/triton/conf_file.c @@ -10,7 +10,7 @@ struct sect_t { struct list_head entry; - + struct conf_sect_t *sect; }; @@ -51,7 +51,7 @@ static int __conf_load(struct conf_ctx *ctx, const char *fname) } r = load_file(&ctx1); - + fclose(ctx1.file); return r; @@ -92,7 +92,7 @@ static int load_file(struct conf_ctx *ctx) fprintf(stderr, "conf_file:%s:%i: sintax error\n", ctx->fname, ctx->line); return -1; } - + if (cur_sect && ctx->items != &cur_sect->items) { fprintf(stderr, "conf_file:%s:%i: cann't open section inside option\n", ctx->fname, ctx->line); return -1; @@ -145,7 +145,7 @@ static int load_file(struct conf_ctx *ctx) if (sect_add_item(ctx, str, str2, raw)) return -1; } - + return 0; } @@ -261,13 +261,13 @@ static struct conf_sect_t *find_sect(const char *name) static struct conf_sect_t *create_sect(const char *name) { struct sect_t *s = _malloc(sizeof(struct sect_t)); - + s->sect = _malloc(sizeof(struct conf_sect_t)); s->sect->name = (char*)_strdup(name); INIT_LIST_HEAD(&s->sect->items); - + list_add_tail(&s->entry, §ions); - + return s->sect; } @@ -293,7 +293,7 @@ static int sect_add_item(struct conf_ctx *ctx, const char *name, char *val, char opt->val = val ? _strdup(val) : NULL; opt->raw = raw; INIT_LIST_HEAD(&opt->items); - + list_add_tail(&opt->entry, ctx->items); if (len) { @@ -313,7 +313,7 @@ static struct conf_option_t *find_item(struct conf_sect_t *sect, const char *nam if (strcmp(opt->name, name) == 0) return opt; } - + return NULL; } @@ -329,7 +329,7 @@ __export char * conf_get_opt(const char *sect, const char *name) if (!s) return NULL; - + opt = find_item(s, name); if (!opt) return NULL; diff --git a/accel-pppd/triton/event.c b/accel-pppd/triton/event.c index 56472c1c..c8a7c431 100644 --- a/accel-pppd/triton/event.c +++ b/accel-pppd/triton/event.c @@ -66,7 +66,7 @@ int __export triton_event_register_handler(int ev_id, triton_event_func func) if (ev_id >= max_events) return -1; - + ev = events[ev_id]; if (!ev) { return -1; @@ -94,7 +94,7 @@ void __export triton_event_fire(int ev_id, void *arg) if (ev_id >= max_events) return; - + ev = events[ev_id]; if (!ev) return; diff --git a/accel-pppd/triton/list.h b/accel-pppd/triton/list.h index b17afab7..a650037f 100644 --- a/accel-pppd/triton/list.h +++ b/accel-pppd/triton/list.h @@ -29,14 +29,14 @@ typedef struct list_head { } while (0) /* - * Insert a new entry between two known consecutive entries. + * Insert a new entry between two known consecutive entries. * * This is only for internal list manipulation where we know * the prev/next entries already! */ static void inline prefetch(void *p){} - + static inline void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next) @@ -105,7 +105,7 @@ static inline void list_del(struct list_head *entry) static inline void list_del_init(struct list_head *entry) { __list_del(entry->prev, entry->next); - INIT_LIST_HEAD(entry); + INIT_LIST_HEAD(entry); } /** @@ -231,7 +231,7 @@ static inline void list_splice_init(struct list_head *list, #define list_for_each_prev(pos, head) \ for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \ pos = pos->prev, prefetch(pos->prev)) - + /** * list_for_each_safe - iterate over a list safe against removal of list entry * @pos: the &struct list_head to use as a loop counter. diff --git a/accel-pppd/triton/loader.c b/accel-pppd/triton/loader.c index 6eb43734..73e767fc 100644 --- a/accel-pppd/triton/loader.c +++ b/accel-pppd/triton/loader.c @@ -96,7 +96,7 @@ int load_modules(const char *name) int __export triton_module_loaded(const char *name) { struct module_t *m; - + list_for_each_entry(m, &modules, entry) { if (strcmp(m->name, name)) continue; diff --git a/accel-pppd/triton/log.c b/accel-pppd/triton/log.c index 668d9e92..f34650f1 100644 --- a/accel-pppd/triton/log.c +++ b/accel-pppd/triton/log.c @@ -66,10 +66,10 @@ void triton_log_error(const char *fmt,...) void triton_log_debug(const char *fmt,...) { va_list ap; - + if (!f_debug) return; - + va_start(ap, fmt); do_log(f_debug, fmt, ap); va_end(ap); diff --git a/accel-pppd/triton/md.c b/accel-pppd/triton/md.c index 6067ff2e..b490d0c0 100644 --- a/accel-pppd/triton/md.c +++ b/accel-pppd/triton/md.c @@ -55,8 +55,8 @@ void md_run(void) void md_terminate(void) { - pthread_cancel(md_thr); - pthread_join(md_thr, NULL); + pthread_cancel(md_thr); + pthread_join(md_thr, NULL); } static void *md_thread(void *arg) @@ -78,7 +78,7 @@ static void *md_thread(void *arg) triton_log_error("md:epoll_wait: %s", strerror(errno)); _exit(-1); } - + for(i = 0; i < n; i++) { h = (struct _triton_md_handler_t *)epoll_events[i].data.ptr; if (!h->ud) @@ -99,7 +99,7 @@ static void *md_thread(void *arg) if (r) triton_thread_wakeup(h->ctx->thread); } - + while (!list_empty(&freed_list2)) { h = list_entry(freed_list2.next, typeof(*h), entry); list_del(&h->entry); @@ -144,7 +144,7 @@ void __export triton_md_unregister_handler(struct triton_md_handler_t *ud, int c close(ud->fd); ud->fd = -1; } - + spin_lock(&h->ctx->lock); h->ud = NULL; list_del(&h->entry); @@ -173,15 +173,15 @@ int __export triton_md_enable_handler(struct triton_md_handler_t *ud, int mode) h->epoll_event.events |= EPOLLIN; if (mode & MD_MODE_WRITE) h->epoll_event.events |= EPOLLOUT; - + if (h->trig_level) h->epoll_event.events |= EPOLLONESHOT; else h->epoll_event.events |= EPOLLET; - + if (events == h->epoll_event.events) return 0; - + if (events) { if (h->armed) r = epoll_ctl(epoll_fd, EPOLL_CTL_MOD, h->ud->fd, &h->epoll_event); @@ -208,15 +208,15 @@ int __export triton_md_disable_handler(struct triton_md_handler_t *ud,int mode) if (!h->epoll_event.events) return 0; - + if (mode & MD_MODE_READ) h->epoll_event.events &= ~EPOLLIN; if (mode & MD_MODE_WRITE) h->epoll_event.events &= ~EPOLLOUT; - + if (!(h->epoll_event.events & (EPOLLIN | EPOLLOUT))) h->epoll_event.events = 0; - + if (events == h->epoll_event.events) return 0; diff --git a/accel-pppd/triton/mempool.c b/accel-pppd/triton/mempool.c index 7c8c56c9..ecc91f34 100644 --- a/accel-pppd/triton/mempool.c +++ b/accel-pppd/triton/mempool.c @@ -84,7 +84,7 @@ mempool_t __export *mempool_create(int size) mempool_t __export *mempool_create2(int size) { struct _mempool_t *p = (struct _mempool_t *)mempool_create(size); - + p->mmap = 1; return (mempool_t *)p; @@ -105,7 +105,7 @@ void __export *mempool_alloc(mempool_t *pool) --p->objects; __sync_sub_and_fetch(&triton_stat.mempool_available, size); - + return it->ptr; #ifdef VALGRIND } @@ -275,7 +275,7 @@ static int mmap_grow(void) } mmap_endptr = ptr + size; - + __sync_add_and_fetch(&triton_stat.mempool_allocated, size); __sync_add_and_fetch(&triton_stat.mempool_available, size); diff --git a/accel-pppd/triton/mempool.h b/accel-pppd/triton/mempool.h index 53eebfb7..9b95af09 100644 --- a/accel-pppd/triton/mempool.h +++ b/accel-pppd/triton/mempool.h @@ -5,7 +5,7 @@ struct mempool_stat_t { - uint32_t allocated; + uint32_t allocated; uint32_t available; }; diff --git a/accel-pppd/triton/options.c b/accel-pppd/triton/options.c index a5214e21..8ff617cf 100644 --- a/accel-pppd/triton/options.c +++ b/accel-pppd/triton/options.c @@ -11,38 +11,38 @@ static struct conf_file_sect_t *sect=NULL; static const char* find_option(const char *name) { struct option_t *opt; - + if (!sect) { sect=conf_file_get_section("options"); if (!sect) return 0; } - + list_for_each_entry(opt,§->items,entry) { if (strcmp(opt->name,name)==0) return opt->val; } - + return NULL; } int triton_get_int_option(const char *str) { const char *val=find_option(str); if (!val) return 0; - + return atoi(val); } const char* triton_get_str_option(const char *str) { const char *val=find_option(str); - + return val; } double triton_get_double_option(const char *str) { const char *val=find_option(str); if (!val) return 0; - + return atof(val); } diff --git a/accel-pppd/triton/timer.c b/accel-pppd/triton/timer.c index 1e4f0612..18599ef3 100644 --- a/accel-pppd/triton/timer.c +++ b/accel-pppd/triton/timer.c @@ -85,7 +85,7 @@ void *timer_thread(void *arg) triton_log_error("timer:epoll_wait: %s", strerror(errno)); _exit(-1); } - + for(i = 0; i < n; i++) { t = (struct _triton_timer_t *)epoll_events[i].data.ptr; if (!t->ud) @@ -141,21 +141,21 @@ int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_ return -1; } - if (fcntl(t->fd, F_SETFL, O_NONBLOCK)) { + if (fcntl(t->fd, F_SETFL, O_NONBLOCK)) { triton_log_error("timer: failed to set nonblocking mode: %s", strerror(errno)); goto out_err; } - + __sync_add_and_fetch(&t->ctx->refs, 1); ud->tpd = t; if (triton_timer_mod(ud, abs_time)) goto out_err; - + spin_lock(&t->ctx->lock); list_add_tail(&t->entry, &t->ctx->timers); spin_unlock(&t->ctx->lock); - + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, t->fd, &t->epoll_event)) { triton_log_error("timer:epoll_ctl: %s", strerror(errno)); spin_lock(&t->ctx->lock); @@ -166,7 +166,7 @@ int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_ } triton_stat.timer_count++; - + return 0; out_err: @@ -214,9 +214,9 @@ void __export triton_timer_del(struct triton_timer_t *ud) pthread_mutex_lock(&freed_list_lock); list_add_tail(&t->entry, &freed_list); pthread_mutex_unlock(&freed_list_lock); - + ud->tpd = NULL; - + triton_stat.timer_count--; } diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c index b190187d..7a494a5a 100644 --- a/accel-pppd/triton/triton.c +++ b/accel-pppd/triton/triton.c @@ -121,13 +121,13 @@ static void* triton_thread(struct _triton_thread_t *thread) log_debug2("thread: %p: sleeping\n", thread); if (!terminate) list_add(&thread->entry2, &sleep_threads); - + if (__sync_sub_and_fetch(&triton_stat.thread_active, 1) == 0 && need_config_reload) { spin_unlock(&threads_lock); __config_reload(config_reload_notify); } else spin_unlock(&threads_lock); - + if (terminate) { spin_lock(&threads_lock); list_del(&thread->entry); @@ -209,7 +209,7 @@ static void ctx_thread(struct _triton_context_t *ctx) spin_unlock(&ctx->lock); __sync_sub_and_fetch(&triton_stat.md_handler_pending, 1); - + h->armed = 0; if ((events & (EPOLLIN | EPOLLERR | EPOLLHUP)) && (h->epoll_event.events & EPOLLIN)) { @@ -242,7 +242,7 @@ static void ctx_thread(struct _triton_context_t *ctx) ctx->pending = 0; spin_unlock(&ctx->lock); - break; + break; } spin_lock(&ctx->lock); @@ -293,7 +293,7 @@ int triton_queue_ctx(struct _triton_context_t *ctx) return 0; } - if (list_empty(&sleep_threads) || need_config_reload || triton_stat.thread_active > thread_count || + if (list_empty(&sleep_threads) || need_config_reload || triton_stat.thread_active > thread_count || (ctx->priority == 0 && triton_stat.thread_count > thread_count_max)) { if (ctx->priority) list_add(&ctx->entry2, &ctx_queue); @@ -403,7 +403,7 @@ void __export triton_context_unregister(struct triton_context_t *ud) terminate = 1; } spin_unlock(&ctx_list_lock); - + if (terminate) { spin_lock(&threads_lock); list_for_each_entry(t, &threads, entry) @@ -415,7 +415,7 @@ void __export triton_context_unregister(struct triton_context_t *ud) void __export triton_context_set_priority(struct triton_context_t *ud, int prio) { struct _triton_context_t *ctx = (struct _triton_context_t *)ud->tpd; - + ctx->priority = prio > 0; } @@ -423,7 +423,7 @@ void __export triton_context_schedule() { struct _triton_context_t *ctx = (struct _triton_context_t *)this_ctx->tpd; struct _triton_thread_t *t = NULL; - + log_debug2("ctx %p: enter schedule\n", ctx); __sync_add_and_fetch(&triton_stat.context_sleeping, 1); __sync_sub_and_fetch(&triton_stat.thread_active, 1); @@ -568,7 +568,7 @@ static void ru_update(struct triton_timer_t *t) clock_gettime(CLOCK_MONOTONIC, &ts); dt = (ts.tv_sec - ru_timestamp.tv_sec) * 1000000 + (ts.tv_nsec - ru_timestamp.tv_nsec) / 1000000; - val = (double)((rusage.ru_utime.tv_sec - ru_utime.tv_sec) * 1000000 + (rusage.ru_utime.tv_usec - ru_utime.tv_usec) + + val = (double)((rusage.ru_utime.tv_sec - ru_utime.tv_sec) * 1000000 + (rusage.ru_utime.tv_usec - ru_utime.tv_usec) + (rusage.ru_stime.tv_sec - ru_stime.tv_sec) * 1000000 + (rusage.ru_stime.tv_usec - ru_stime.tv_usec)) / dt * 100; triton_stat.cpu = val; @@ -637,7 +637,7 @@ int __export triton_load_modules(const char *mod_sect) list_del(&i->entry); free(i); } - + return 0; } @@ -721,7 +721,7 @@ void __export triton_terminate() spin_unlock(&threads_lock); sleep(1); } - + md_terminate(); timer_terminate(); } diff --git a/accel-pppd/triton/triton.h b/accel-pppd/triton/triton.h index 89e8577c..b66737cf 100644 --- a/accel-pppd/triton/triton.h +++ b/accel-pppd/triton/triton.h @@ -49,7 +49,7 @@ struct conf_option_t struct conf_sect_t { - const char *name; + const char *name; struct list_head items; }; diff --git a/accel-pppd/triton/triton_p.h b/accel-pppd/triton/triton_p.h index 2bbccbd1..6c9f884d 100644 --- a/accel-pppd/triton/triton_p.h +++ b/accel-pppd/triton/triton_p.h @@ -24,10 +24,10 @@ struct _triton_context_t { struct list_head entry; struct list_head entry2; - + spinlock_t lock; struct _triton_thread_t *thread; - + struct list_head handlers; struct list_head timers; struct list_head pending_handlers; |