MCPcopy Create free account
hub / github.com/F-Stack/f-stack / in6_gre_setup_socket

Function in6_gre_setup_socket

freebsd/netinet6/ip6_gre.c:259–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257}
258
259static int
260in6_gre_setup_socket(struct gre_softc *sc)
261{
262 struct sockopt sopt;
263 struct sockaddr_in6 sin6;
264 struct in6_gre_socket *s;
265 struct gre_socket *gs;
266 int error, value;
267
268 /*
269 * NOTE: we are protected with gre_ioctl_sx lock.
270 *
271 * First check that socket is already configured.
272 * If so, check that source addres was not changed.
273 * If address is different, check that there are no other tunnels
274 * and close socket.
275 */
276 gs = sc->gre_so;
277 if (gs != NULL) {
278 s = __containerof(gs, struct in6_gre_socket, base);
279 if (!IN6_ARE_ADDR_EQUAL(&s->addr, &sc->gre_oip6.ip6_src)) {
280 if (CK_LIST_EMPTY(&gs->list)) {
281 CK_LIST_REMOVE(gs, chain);
282 soclose(gs->so);
283 NET_EPOCH_CALL(gre_sofree, &gs->epoch_ctx);
284 }
285 gs = sc->gre_so = NULL;
286 }
287 }
288
289 if (gs == NULL) {
290 /*
291 * Check that socket for given address is already
292 * configured.
293 */
294 gs = in6_gre_lookup_socket(&sc->gre_oip6.ip6_src);
295 if (gs == NULL) {
296 s = malloc(sizeof(*s), M_GRE, M_WAITOK | M_ZERO);
297 s->addr = sc->gre_oip6.ip6_src;
298 gs = &s->base;
299
300 error = socreate(sc->gre_family, &gs->so,
301 SOCK_DGRAM, IPPROTO_UDP, curthread->td_ucred,
302 curthread);
303 if (error != 0) {
304 if_printf(GRE2IFP(sc),
305 "cannot create socket: %d\n", error);
306 free(s, M_GRE);
307 return (error);
308 }
309
310 error = udp_set_kernel_tunneling(gs->so,
311 in6_gre_udp_input, NULL, gs);
312 if (error != 0) {
313 if_printf(GRE2IFP(sc),
314 "cannot set UDP tunneling: %d\n", error);
315 goto fail;
316 }

Callers 1

in6_gre_attachFunction · 0.85

Calls 11

socloseFunction · 0.85
in6_gre_lookup_socketFunction · 0.85
mallocFunction · 0.85
socreateFunction · 0.85
if_printfFunction · 0.85
udp_set_kernel_tunnelingFunction · 0.85
memsetFunction · 0.85
sosetoptFunction · 0.85
sa6_recoverscopeFunction · 0.85
sobindFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected