diff options
author | root <you@example.com> | 2016-11-13 22:20:45 +0000 |
---|---|---|
committer | root <you@example.com> | 2016-11-13 22:20:45 +0000 |
commit | e33a2b9c3fdfd7e89e1daa8c4407bec9dc02dc17 (patch) | |
tree | 6920324c3735b02c366fedcb661a384a032f288a /accel-pppd/ctrl/pppoe/pppoe.c | |
parent | 7de0d2d00be552dede15dfd02c9e423dda7eb6f5 (diff) | |
download | accel-ppp-e33a2b9c3fdfd7e89e1daa8c4407bec9dc02dc17.tar.gz accel-ppp-e33a2b9c3fdfd7e89e1daa8c4407bec9dc02dc17.zip |
Add possibility to specify multiple service names, add option accept-any-service to provide backward compatibility with old accel-ppp
Diffstat (limited to 'accel-pppd/ctrl/pppoe/pppoe.c')
-rw-r--r-- | accel-pppd/ctrl/pppoe/pppoe.c | 75 |
1 files changed, 54 insertions, 21 deletions
diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index a4d1ca92..a93e315e 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -88,7 +88,8 @@ struct iplink_arg { }; int conf_verbose; -char *conf_service_name; +char *conf_service_name[255]; +int conf_accept_any_service; char *conf_ac_name; int conf_ifname_in_sid; char *conf_pado_delay; @@ -758,8 +759,13 @@ static void pppoe_send_PADO(struct pppoe_serv_t *serv, const uint8_t *addr, cons setup_header(pack, serv->hwaddr, addr, CODE_PADO, 0); add_tag(pack, TAG_AC_NAME, (uint8_t *)conf_ac_name, strlen(conf_ac_name)); - if (conf_service_name) - add_tag(pack, TAG_SERVICE_NAME, (uint8_t *)conf_service_name, strlen(conf_service_name)); + if (conf_service_name[0]) { + int i = 0; + do { + add_tag(pack, TAG_SERVICE_NAME, (uint8_t *)conf_service_name, strlen(conf_service_name[i])); + i++; + } while(conf_service_name[i]); + } if (service_name) add_tag2(pack, service_name); @@ -939,7 +945,7 @@ static void pppoe_recv_PADI(struct pppoe_serv_t *serv, uint8_t *pack, int size) struct pppoe_tag *host_uniq_tag = NULL; struct pppoe_tag *relay_sid_tag = NULL; struct pppoe_tag *service_name_tag = NULL; - int len, n, service_match = conf_service_name == NULL; + int len, n, service_match = conf_service_name[0] == NULL; struct delayed_pado_t *pado; struct timespec ts; uint16_t ppp_max_payload = 0; @@ -973,12 +979,16 @@ static void pppoe_recv_PADI(struct pppoe_serv_t *serv, uint8_t *pack, int size) case TAG_END_OF_LIST: break; case TAG_SERVICE_NAME: - if (conf_service_name) { - if (ntohs(tag->tag_len) != strlen(conf_service_name)) - break; - if (memcmp(tag->tag_data, conf_service_name, ntohs(tag->tag_len))) - break; - service_match = 1; + if (conf_service_name[0]) { + int svc_index = 0; + do { + if (ntohs(tag->tag_len) == strlen(conf_service_name[svc_index]) && + memcmp(tag->tag_data, conf_service_name[svc_index], ntohs(tag->tag_len)) == 0) { + service_match = 1; + break; + } + svc_index++; + } while(conf_service_name[svc_index]); } else service_name_tag = tag; break; @@ -998,7 +1008,7 @@ static void pppoe_recv_PADI(struct pppoe_serv_t *serv, uint8_t *pack, int size) if (conf_verbose) print_packet(serv->ifname, "recv", pack); - if (!service_match) { + if (!service_match && !conf_accept_any_service) { if (conf_verbose) log_warn("pppoe: discarding PADI packet (Service-Name mismatch)\n"); return; @@ -1103,12 +1113,16 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size) service_name_tag = tag; if (tag->tag_len == 0) service_match = 1; - else if (conf_service_name) { - if (ntohs(tag->tag_len) != strlen(conf_service_name)) - break; - if (memcmp(tag->tag_data, conf_service_name, ntohs(tag->tag_len))) - break; - service_match = 1; + else if (conf_service_name[0]) { + int svc_index = 0; + do { + if (ntohs(tag->tag_len) == strlen(conf_service_name[svc_index]) && + memcmp(tag->tag_data, conf_service_name[svc_index], ntohs(tag->tag_len)) == 0) { + service_match = 1; + break; + } + svc_index++; + } while(conf_service_name[svc_index]); } else { service_match = 1; } @@ -1154,7 +1168,7 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size) return; } - if (!service_match) { + if (!service_match && !conf_accept_any_service) { if (conf_verbose) log_warn("pppoe: Service-Name mismatch\n"); pppoe_send_err(serv, ethhdr->h_source, host_uniq_tag, relay_sid_tag, CODE_PADS, TAG_SERVICE_NAME_ERROR); @@ -1883,6 +1897,10 @@ static void load_config(void) if (opt) conf_verbose = atoi(opt); + opt = conf_get_opt("pppoe", "accept-any-service"); + if (opt) + conf_accept_any_service = atoi(opt); + opt = conf_get_opt("pppoe", "ac-name"); if (!opt) opt = conf_get_opt("pppoe", "AC-Name"); @@ -1897,9 +1915,23 @@ static void load_config(void) if (!opt) opt = conf_get_opt("pppoe", "Service-Name"); if (opt) { - if (conf_service_name) - _free(conf_service_name); - conf_service_name = _strdup(opt); + if (conf_service_name[0]) { + int i = 0; + do { + _free(conf_service_name[i]); + i++; + } while(conf_service_name[i]); + conf_service_name[0] = NULL; + } + char *conf_service_name_string = _strdup(opt); + char *p = strtok (conf_service_name_string, ","); + int i = 0; + while (p != NULL && i<255) { + conf_service_name[i++] = _strdup(p); + p = strtok(NULL, ","); + } + conf_service_name[i] = NULL; + _free(conf_service_name_string); } opt = conf_get_opt("pppoe", "ifname-in-sid"); @@ -2015,6 +2047,7 @@ static void pppoe_init(void) conn_pool = mempool_create(sizeof(struct pppoe_conn_t)); pado_pool = mempool_create(sizeof(struct delayed_pado_t)); padi_pool = mempool_create(sizeof(struct padi_t)); + conf_service_name[0] = NULL; if (!conf_get_section("pppoe")) { log_error("pppoe: no configuration, disabled...\n"); |