diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2013-09-06 10:55:35 +0400 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-09-06 10:55:35 +0400 |
commit | 7ea5ddfb8cf3a2507b901882bd92c5c946e372c8 (patch) | |
tree | a201079f18621a2037ac6c65f1107f814b141843 /accel-pppd/ctrl/ipoe/dhcpv4.c | |
parent | 5f8334da2d874e0be028ad03376574de1598f0cd (diff) | |
download | accel-ppp-7ea5ddfb8cf3a2507b901882bd92c5c946e372c8.tar.gz accel-ppp-7ea5ddfb8cf3a2507b901882bd92c5c946e372c8.zip |
ipoe: various fixes in relay operation
Diffstat (limited to 'accel-pppd/ctrl/ipoe/dhcpv4.c')
-rw-r--r-- | accel-pppd/ctrl/ipoe/dhcpv4.c | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c index fa76344..fc2a9d3 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4.c +++ b/accel-pppd/ctrl/ipoe/dhcpv4.c @@ -535,10 +535,12 @@ static int dhcpv4_relay_read(struct triton_md_handler_t *h) continue; } + pthread_mutex_lock(&relay_lock); list_for_each_entry(c, &r->ctx_list, entry) { dhcpv4_packet_ref(pack); triton_context_call(c->ctx, c->recv, pack); } + pthread_mutex_unlock(&relay_lock); dhcpv4_packet_free(pack); } @@ -790,16 +792,14 @@ out_err: return 0; } -struct dhcpv4_relay *dhcpv4_relay_create(const char *_addr, const char *_giaddr, struct triton_context_t *ctx, triton_event_func recv) +struct dhcpv4_relay *dhcpv4_relay_create(const char *_addr, in_addr_t giaddr, struct triton_context_t *ctx, triton_event_func recv) { char str[17], *ptr; struct dhcpv4_relay *r; in_addr_t addr;// = inet_addr(_addr); int port = DHCP_SERV_PORT; - in_addr_t giaddr;// = inet_addr(_giaddr); struct sockaddr_in raddr; struct sockaddr_in laddr; - socklen_t len = sizeof(laddr); int sock = -1; int f = 1; struct dhcpv4_relay_ctx *c; @@ -818,22 +818,6 @@ struct dhcpv4_relay *dhcpv4_relay_create(const char *_addr, const char *_giaddr, raddr.sin_addr.s_addr = addr; raddr.sin_port = htons(port); - if (_giaddr) - giaddr = inet_addr(_giaddr); - else { - sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); - - if (connect(sock, &raddr, sizeof(raddr))) { - log_error("dhcpv4: relay: %s: connect: %s\n", _addr, strerror(errno)); - goto out_err; - } - - getsockname(sock, &laddr, &len); - giaddr = laddr.sin_addr.s_addr; - - close(sock); - } - memset(&laddr, 0, sizeof(laddr)); laddr.sin_family = AF_INET; laddr.sin_addr.s_addr = giaddr; @@ -896,13 +880,20 @@ found: out_err_unlock: pthread_mutex_unlock(&relay_lock); -out_err: if (sock != -1) close(sock); _free(r); return NULL; } +static void __dhcpv4_relay_free(struct dhcpv4_relay *r) +{ + triton_md_unregister_handler(&r->hnd); + close(r->hnd.fd); + triton_context_unregister(&r->ctx); + _free(r); +} + void dhcpv4_relay_free(struct dhcpv4_relay *r, struct triton_context_t *ctx) { struct dhcpv4_relay_ctx *c; @@ -918,11 +909,7 @@ void dhcpv4_relay_free(struct dhcpv4_relay *r, struct triton_context_t *ctx) if (list_empty(&r->ctx_list)) { list_del(&r->entry); - - triton_md_unregister_handler(&r->hnd); - close(r->hnd.fd); - triton_context_unregister(&r->ctx); - _free(r); + triton_context_call(&r->ctx, (triton_event_func)__dhcpv4_relay_free, r); } pthread_mutex_unlock(&relay_lock); } |