diff options
author | Kozlov Dmitry <xeb@mail.ru> | 2013-01-24 23:52:59 +0400 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2013-01-24 23:52:59 +0400 |
commit | 4c7ad9a5f8839d2e13c6f012c7cd3653e04b98b7 (patch) | |
tree | 570f0babf2205bb75e486842c7f600da91698041 /accel-pppd/ppp | |
parent | 45026d43f6cfbe0f6efa446b47629cb948db5a9d (diff) | |
download | accel-ppp-4c7ad9a5f8839d2e13c6f012c7cd3653e04b98b7.tar.gz accel-ppp-4c7ad9a5f8839d2e13c6f012c7cd3653e04b98b7.zip |
add missing files
Diffstat (limited to 'accel-pppd/ppp')
-rw-r--r-- | accel-pppd/ppp/ipcp_opt_wins.c | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/accel-pppd/ppp/ipcp_opt_wins.c b/accel-pppd/ppp/ipcp_opt_wins.c new file mode 100644 index 00000000..f65b945f --- /dev/null +++ b/accel-pppd/ppp/ipcp_opt_wins.c @@ -0,0 +1,209 @@ +#include <stdlib.h> +#include <string.h> +#include <arpa/inet.h> + +#include "ppp.h" +#include "ppp_ipcp.h" +#include "log.h" +#include "ipdb.h" +#include "events.h" + +#include "memdebug.h" + +static in_addr_t conf_wins1; +static in_addr_t conf_wins2; + +static struct ipcp_option_t *wins1_init(struct ppp_ipcp_t *ipcp); +static struct ipcp_option_t *wins2_init(struct ppp_ipcp_t *ipcp); +static void wins_free(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt); +static int wins_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr); +static int wins_send_conf_nak(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr); +static int wins_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr); +static int wins_recv_conf_rej(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr); +static void wins1_print(void (*print)(const char *fmt,...), struct ipcp_option_t*, uint8_t *ptr); +static void wins2_print(void (*print)(const char *fmt,...), struct ipcp_option_t*, uint8_t *ptr); + +struct wins_option_t +{ + struct ipcp_option_t opt; + in_addr_t addr; + int rejected; +}; + +static struct ipcp_option_handler_t wins1_opt_hnd = { + .init = wins1_init, + .send_conf_req = wins_send_conf_req, + .send_conf_nak = wins_send_conf_nak, + .recv_conf_req = wins_recv_conf_req, + .recv_conf_rej = wins_recv_conf_rej, + .free = wins_free, + .print = wins1_print, +}; + +static struct ipcp_option_handler_t wins2_opt_hnd = { + .init = wins2_init, + .send_conf_req = wins_send_conf_req, + .send_conf_nak = wins_send_conf_nak, + .recv_conf_req = wins_recv_conf_req, + .recv_conf_rej = wins_recv_conf_rej, + .free = wins_free, + .print = wins2_print, +}; + +static struct ipcp_option_t *wins1_init(struct ppp_ipcp_t *ipcp) +{ + struct wins_option_t *wins_opt = _malloc(sizeof(*wins_opt)); + memset(wins_opt, 0, sizeof(*wins_opt)); + wins_opt->opt.id = CI_WINS1; + wins_opt->opt.len = 6; + + return &wins_opt->opt; +} + +static struct ipcp_option_t *wins2_init(struct ppp_ipcp_t *ipcp) +{ + struct wins_option_t *wins_opt = _malloc(sizeof(*wins_opt)); + memset(wins_opt, 0, sizeof(*wins_opt)); + wins_opt->opt.id = CI_WINS2; + wins_opt->opt.len = 6; + + return &wins_opt->opt; +} + +static void wins_free(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt) +{ + struct wins_option_t *wins_opt=container_of(opt,typeof(*wins_opt),opt); + + _free(wins_opt); +} + +static int wins_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr) +{ + struct wins_option_t *wins_opt = container_of(opt, typeof(*wins_opt), opt); + struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t *)ptr; + + if (!wins_opt->addr || wins_opt->rejected) + return 0; + + opt32->hdr.id = wins_opt->opt.id; + opt32->hdr.len = 6; + opt32->val = 0; + + return 6; +} + +static int wins_send_conf_nak(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr) +{ + struct wins_option_t *wins_opt = container_of(opt, typeof(*wins_opt), opt); + struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t *)ptr; + opt32->hdr.id = wins_opt->opt.id; + opt32->hdr.len = 6; + opt32->val = wins_opt->addr; + return 6; +} + +static int wins_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr) +{ + struct wins_option_t *wins_opt = container_of(opt, typeof(*wins_opt), opt); + struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t*)ptr; + + if (opt32->hdr.len != 6) + return IPCP_OPT_REJ; + + if (!wins_opt->addr) { + if (wins_opt->opt.id == CI_WINS1 && conf_wins1) + wins_opt->addr=conf_wins1; + else if (wins_opt->opt.id == CI_WINS2 && conf_wins2) + wins_opt->addr=conf_wins2; + + if (!wins_opt->addr) { + wins_opt->addr = opt32->val; + return IPCP_OPT_ACK; + } + } + + if (wins_opt->addr == opt32->val) + return IPCP_OPT_ACK; + + return IPCP_OPT_NAK; +} + +static int wins_recv_conf_rej(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt, uint8_t *ptr) +{ + struct wins_option_t *wins_opt = container_of(opt, typeof(*wins_opt), opt); + + wins_opt->rejected = 1; + + return 0; +} + +static void wins1_print(void (*print)(const char *fmt,...), struct ipcp_option_t *opt, uint8_t *ptr) +{ + struct wins_option_t *wins_opt = container_of(opt, typeof(*wins_opt), opt); + struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t *)ptr; + struct in_addr in; + + if (ptr) + in.s_addr = opt32->val; + else + in.s_addr = wins_opt->addr; + + print("<wins1 %s>", inet_ntoa(in)); +} + +static void wins2_print(void (*print)(const char *fmt,...), struct ipcp_option_t *opt, uint8_t *ptr) +{ + struct wins_option_t *wins_opt = container_of(opt, typeof(*wins_opt), opt); + struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t *)ptr; + struct in_addr in; + + if (ptr) + in.s_addr = opt32->val; + else + in.s_addr = wins_opt->addr; + + print("<wins2 %s>", inet_ntoa(in)); +} + +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; + + ppp = container_of(ev->ses, typeof(*ppp), ses); + + wins_opt = container_of(ipcp_find_option(ppp, &wins1_opt_hnd), typeof(*wins_opt), opt); + wins_opt->addr = ev->wins1; + + wins_opt = container_of(ipcp_find_option(ppp, &wins2_opt_hnd), typeof(*wins_opt), opt); + wins_opt->addr = ev->wins2; +} + +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); +} + +static void wins_opt_init() +{ + ipcp_option_register(&wins1_opt_hnd); + ipcp_option_register(&wins2_opt_hnd); + + load_config(); + triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); + + triton_event_register_handler(EV_WINS, (triton_event_func)ev_wins); +} + +DEFINE_INIT(4, wins_opt_init); |