From 398c8ee38d6a82ce4e2a461eebd7b5fbca8ecf94 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 23 Aug 2016 14:54:35 +0200 Subject: libndp: move ndp_sock_{open,close}() after msg parsing functions In a following commit ndp_sock_open() will refer to ndp_msg_type_info_list to add a filter on handled ICMP types. Move the open and close functions below in a dedicated section. Signed-off-by: Beniamino Galvani Signed-off-by: Jiri Pirko --- libndp/libndp.c | 113 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 53 deletions(-) (limited to 'libndp') diff --git a/libndp/libndp.c b/libndp/libndp.c index b7172fa..66db796 100644 --- a/libndp/libndp.c +++ b/libndp/libndp.c @@ -230,59 +230,6 @@ static const char *str_in6_addr(struct in6_addr *addr) * @short_description: functions that actually implements NDP */ -static int ndp_sock_open(struct ndp *ndp) -{ - int sock; - //struct icmp6_filter flt; - int ret; - int err; - int val; - - sock = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6); - if (sock == -1) { - err(ndp, "Failed to create ICMP6 socket."); - return -errno; - } - - val = 1; - ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, - &val, sizeof(val)); - if (ret == -1) { - err(ndp, "Failed to setsockopt IPV6_RECVPKTINFO."); - err = -errno; - goto close_sock; - } - - val = 255; - ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, - &val, sizeof(val)); - if (ret == -1) { - err(ndp, "Failed to setsockopt IPV6_MULTICAST_HOPS."); - err = -errno; - goto close_sock; - } - - val = 1; - ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, - &val, sizeof(val)); - if (ret == -1) { - err(ndp, "Failed to setsockopt IPV6_RECVHOPLIMIT,."); - err = -errno; - goto close_sock; - } - - ndp->sock = sock; - return 0; -close_sock: - close(sock); - return err; -} - -static void ndp_sock_close(struct ndp *ndp) -{ - close(ndp->sock); -} - struct ndp_msggeneric { void *dataptr; /* must be first */ }; @@ -336,6 +283,7 @@ struct ndp_msg_type_info { bool (*addrto_validate)(struct in6_addr *addr); }; + static void ndp_msg_addrto_adjust_all_nodes(struct in6_addr *addr) { struct in6_addr any = IN6ADDR_ANY_INIT; @@ -1781,6 +1729,65 @@ free_msg: } +/** + * SECTION: socket open/close functions + * @short_description: functions for opening and closing the ICMPv6 raw socket + */ + +static int ndp_sock_open(struct ndp *ndp) +{ + int sock; + //struct icmp6_filter flt; + int ret; + int err; + int val; + + sock = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6); + if (sock == -1) { + err(ndp, "Failed to create ICMP6 socket."); + return -errno; + } + + val = 1; + ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, + &val, sizeof(val)); + if (ret == -1) { + err(ndp, "Failed to setsockopt IPV6_RECVPKTINFO."); + err = -errno; + goto close_sock; + } + + val = 255; + ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, + &val, sizeof(val)); + if (ret == -1) { + err(ndp, "Failed to setsockopt IPV6_MULTICAST_HOPS."); + err = -errno; + goto close_sock; + } + + val = 1; + ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, + &val, sizeof(val)); + if (ret == -1) { + err(ndp, "Failed to setsockopt IPV6_RECVHOPLIMIT,."); + err = -errno; + goto close_sock; + } + + ndp->sock = sock; + return 0; +close_sock: + close(sock); + return err; +} + +static void ndp_sock_close(struct ndp *ndp) +{ + close(ndp->sock); +} + + /** * SECTION: msgrcv handler * @short_description: msgrcv handler and related stuff -- cgit v1.2.1