diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2016-08-23 14:54:35 +0200 |
---|---|---|
committer | Jiri Pirko <jiri@mellanox.com> | 2016-08-29 09:06:07 +0200 |
commit | 398c8ee38d6a82ce4e2a461eebd7b5fbca8ecf94 (patch) | |
tree | a8cc2bc6706848e7a1fea8ef4c512e742bbb2a5b | |
parent | 94e9a082d76414f82794b0c9817d0c24e3868275 (diff) | |
download | libndp-398c8ee38d6a82ce4e2a461eebd7b5fbca8ecf94.tar.gz |
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 <bgalvani@redhat.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
-rw-r--r-- | libndp/libndp.c | 113 |
1 files changed, 60 insertions, 53 deletions
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; @@ -1782,6 +1730,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 */ |