| 361 | } |
| 362 | |
| 363 | static int |
| 364 | in_gre_attach(struct gre_softc *sc) |
| 365 | { |
| 366 | struct grehdr *gh; |
| 367 | int error; |
| 368 | |
| 369 | if (sc->gre_options & GRE_UDPENCAP) { |
| 370 | sc->gre_csumflags = CSUM_UDP; |
| 371 | sc->gre_hlen = sizeof(struct greudp); |
| 372 | sc->gre_oip.ip_p = IPPROTO_UDP; |
| 373 | gh = &sc->gre_udphdr->gi_gre; |
| 374 | gre_update_udphdr(sc, &sc->gre_udp, |
| 375 | in_pseudo(sc->gre_oip.ip_src.s_addr, |
| 376 | sc->gre_oip.ip_dst.s_addr, 0)); |
| 377 | } else { |
| 378 | sc->gre_hlen = sizeof(struct greip); |
| 379 | sc->gre_oip.ip_p = IPPROTO_GRE; |
| 380 | gh = &sc->gre_iphdr->gi_gre; |
| 381 | } |
| 382 | sc->gre_oip.ip_v = IPVERSION; |
| 383 | sc->gre_oip.ip_hl = sizeof(struct ip) >> 2; |
| 384 | gre_update_hdr(sc, gh); |
| 385 | |
| 386 | /* |
| 387 | * If we return error, this means that sc is not linked, |
| 388 | * and caller should reset gre_family and free(sc->gre_hdr). |
| 389 | */ |
| 390 | if (sc->gre_options & GRE_UDPENCAP) { |
| 391 | error = in_gre_setup_socket(sc); |
| 392 | if (error != 0) |
| 393 | return (error); |
| 394 | } else |
| 395 | CK_LIST_INSERT_HEAD(&GRE_HASH_SC(sc), sc, chain); |
| 396 | CK_LIST_INSERT_HEAD(&GRE_SRCHASH(sc->gre_oip.ip_src.s_addr), |
| 397 | sc, srchash); |
| 398 | |
| 399 | /* Set IFF_DRV_RUNNING if interface is ready */ |
| 400 | in_gre_set_running(sc); |
| 401 | return (0); |
| 402 | } |
| 403 | |
| 404 | int |
| 405 | in_gre_setopts(struct gre_softc *sc, u_long cmd, uint32_t value) |
no test coverage detected