Changeset 988 for vendor/current/source3/lib/addrchange.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/lib/addrchange.c
r740 r988 26 26 #include "linux/netlink.h" 27 27 #include "linux/rtnetlink.h" 28 #include "lib/ async_req/async_sock.h"28 #include "lib/tsocket/tsocket.h" 29 29 30 30 struct addrchange_context { 31 intsock;31 struct tdgram_context *sock; 32 32 }; 33 34 static int addrchange_context_destructor(struct addrchange_context *c);35 33 36 34 NTSTATUS addrchange_context_create(TALLOC_CTX *mem_ctx, … … 40 38 struct sockaddr_nl addr; 41 39 NTSTATUS status; 40 int sock = -1; 42 41 int res; 42 bool ok; 43 43 44 44 ctx = talloc(mem_ctx, struct addrchange_context); … … 47 47 } 48 48 49 ctx->sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); 50 if (ctx->sock == -1) { 51 status = map_nt_error_from_unix(errno); 52 goto fail; 53 } 54 talloc_set_destructor(ctx, addrchange_context_destructor); 49 sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); 50 if (sock == -1) { 51 status = map_nt_error_from_unix(errno); 52 goto fail; 53 } 54 55 ok = smb_set_close_on_exec(sock); 56 if (!ok) { 57 status = map_nt_error_from_unix(errno); 58 goto fail; 59 } 60 61 res = set_blocking(sock, false); 62 if (res == -1) { 63 status = map_nt_error_from_unix(errno); 64 goto fail; 65 } 55 66 56 67 /* … … 61 72 addr.nl_groups = RTMGRP_IPV6_IFADDR | RTMGRP_IPV4_IFADDR; 62 73 63 res = bind(ctx->sock, (struct sockaddr *)(void *)&addr, sizeof(addr)); 74 res = bind(sock, (struct sockaddr *)(void *)&addr, sizeof(addr)); 75 if (res == -1) { 76 status = map_nt_error_from_unix(errno); 77 goto fail; 78 } 79 80 res = tdgram_bsd_existing_socket(ctx, sock, &ctx->sock); 64 81 if (res == -1) { 65 82 status = map_nt_error_from_unix(errno); … … 70 87 return NT_STATUS_OK; 71 88 fail: 89 if (sock != -1) { 90 close(sock); 91 } 72 92 TALLOC_FREE(ctx); 73 93 return status; 74 }75 76 static int addrchange_context_destructor(struct addrchange_context *c)77 {78 if (c->sock != -1) {79 close(c->sock);80 c->sock = -1;81 }82 return 0;83 94 } 84 95 … … 86 97 struct tevent_context *ev; 87 98 struct addrchange_context *ctx; 88 uint8_t buf[8192]; 89 struct sockaddr_storage fromaddr; 90 socklen_t fromaddr_len; 99 uint8_t *buf; 100 struct tsocket_address *fromaddr; 91 101 92 102 enum addrchange_type type; … … 110 120 state->ctx = ctx; 111 121 112 state->fromaddr_len = sizeof(state->fromaddr); 113 subreq = recvfrom_send(state, state->ev, state->ctx->sock, 114 state->buf, sizeof(state->buf), 0, 115 &state->fromaddr, &state->fromaddr_len); 122 subreq = tdgram_recvfrom_send(state, state->ev, state->ctx->sock); 116 123 if (tevent_req_nomem(subreq, req)) { 117 124 return tevent_req_post(req, state->ev); … … 127 134 struct addrchange_state *state = tevent_req_data( 128 135 req, struct addrchange_state); 129 struct sockaddr_nl *addr; 136 union { 137 struct sockaddr sa; 138 struct sockaddr_nl nl; 139 struct sockaddr_storage ss; 140 } fromaddr; 130 141 struct nlmsghdr *h; 131 142 struct ifaddrmsg *ifa; … … 136 147 bool found; 137 148 138 received = recvfrom_recv(subreq, &err); 149 received = tdgram_recvfrom_recv(subreq, &err, state, 150 &state->buf, 151 &state->fromaddr); 139 152 TALLOC_FREE(subreq); 140 153 if (received == -1) { 141 DEBUG(10, (" recvfrom returned %s\n", strerror(errno)));154 DEBUG(10, ("tdgram_recvfrom_recv returned %s\n", strerror(err))); 142 155 tevent_req_nterror(req, map_nt_error_from_unix(err)); 143 156 return; 144 157 } 145 if ((state->fromaddr_len != sizeof(struct sockaddr_nl)) 146 || (state->fromaddr.ss_family != AF_NETLINK)) { 158 len = tsocket_address_bsd_sockaddr(state->fromaddr, 159 &fromaddr.sa, 160 sizeof(fromaddr)); 161 162 if ((len != sizeof(fromaddr.nl) || 163 fromaddr.sa.sa_family != AF_NETLINK)) 164 { 147 165 DEBUG(10, ("Got message from wrong addr\n")); 148 166 goto retry; 149 167 } 150 168 151 addr = (struct sockaddr_nl *)(void *)&state->addr; 152 if (addr->nl_pid != 0) { 169 if (fromaddr.nl.nl_pid != 0) { 153 170 DEBUG(10, ("Got msg from pid %d, not from the kernel\n", 154 (int) addr->nl_pid));171 (int)fromaddr.nl.nl_pid)); 155 172 goto retry; 156 173 } … … 247 264 248 265 retry: 249 state->fromaddr_len = sizeof(state->fromaddr);250 subreq = recvfrom_send(state, state->ev, state->ctx->sock,251 state->buf, sizeof(state->buf), 0, 252 &state->fromaddr, &state->fromaddr_len);266 TALLOC_FREE(state->buf); 267 TALLOC_FREE(state->fromaddr); 268 269 subreq = tdgram_recvfrom_send(state, state->ev, state->ctx->sock); 253 270 if (tevent_req_nomem(subreq, req)) { 254 271 return; … … 265 282 266 283 if (tevent_req_is_nterror(req, &status)) { 284 tevent_req_received(req); 267 285 return status; 268 286 } … … 270 288 *type = state->type; 271 289 *addr = state->addr; 290 tevent_req_received(req); 272 291 return NT_STATUS_OK; 273 292 }
Note:
See TracChangeset
for help on using the changeset viewer.