summaryrefslogtreecommitdiff
path: root/libndp
Commit message (Collapse)AuthorAgeFilesLines
* libndp,ndptool: use poll() instead of select()Beniamino Galvani2021-03-051-11/+9
| | | | | | | | | | | select() doesn't support file descriptors greater than 1023. If the program has many files open, the socket descriptor can be > 1023 and then FD_SET(fd, &rfds) causes a buffer overflow. Switch to poll() and ppoll() which don't have this limitation. Signed-off-by: Beniamino Galvani <bgalvani@redhat.com> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
* libndp: avoid static buffer for debug string in ndp_sock_recv()Thomas Haller2021-01-281-5/+4
| | | | | | | | libndp should be thread safe. There is really no need to use a static buffer in this case. Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
* libndp: use thread local variables for static return argumentsThomas Haller2021-01-272-3/+4
| | | | | | | | | | | | | | | | | | | | | libndp should be thread safe. That doesn't mean, that one "struct ndp" can be used by multiple threads without locking. But it should be reasonably possible to use the library in a multi threaded scenario. Some API functions return values that are cached in static variables. That makes these function (and the entire library) not thread safe. Fix that by using gcc's __thread specifier for thread local storage. This is also supported by clang. Currently, it's not clear whether all compiler that libndp supports, support this. I expect that to be the case. Hence, the NDP_THREAD define does not try to workaround such (yet unknown) build environments. However, if the need arises, we can easily extend the NDP_THREAD define with some conditional compilation. Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
* ndptool: add -D dest supportHangbin Liu2019-09-161-10/+32
| | | | | | | | | | | | | | This patch add -D dest option, with this option a user could set the dest address in IPv6 header for solicited NS/NA message For function ndp_msg_addrto_adjust_solicit_multi(), I moved the check in ndp_msg_target_set() instead of in the function itself. I also use reverse christmas tree variable order in the main() function of ndptool.c. Signed-off-by: Hangbin Liu <haliu@redhat.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* libndp: fix nd_msg typo when setting target addressHangbin Liu2019-09-121-2/+2
| | | | | | | | When setting the target address of nd_msg, I set the ns/na type reversed. Fixes: acccd780df517 ("ndptool: add -T target support") Signed-off-by: Hangbin Liu <haliu@redhat.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* libndp: close sockfd after using to avoid handle leakHangbin Liu2019-01-071-4/+8
| | | | | | Fixes: acccd780df517 ("ndptool: add -T target support") Signed-off-by: Hangbin Liu <haliu@redhat.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* ndptool: add -T target supportHangbin Liu2018-08-061-0/+121
| | | | | | | | | | | | | | | | Currently ndptool can send a Neighbour Solicitation, but does not target an IP address, so the NS packet doesn't really make sense. Extend ndptool to target a destination for Neighbour Solicitation. v2: 1) remove function ipv6_addr_is_multicast() 2) inline some help functions. 3) update code style. 4) rename parameter -d/--dest to -T/--target Signed-off-by: Hangbin Liu <haliu@redhat.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* libndp: apply filter to raw socket to only accept ND messagesBeniamino Galvani2016-08-291-1/+13
| | | | | | | | | Use setsockopt() to set a filter on the socket and accept only Neighbor discover packets. This avoids wasting processing power on frames we're not interested in. Signed-off-by: Beniamino Galvani <bgalvani@redhat.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* libndp: move ndp_sock_{open,close}() after msg parsing functionsBeniamino Galvani2016-08-291-53/+60
| | | | | | | | | 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>
* libndb: reject redirect and router advertisements from non-link-localLubomir Rintel2016-05-171-1/+13
| | | | | | | | | | RFC4861 suggests that these messages should only originate from link-local addresses in 6.1.2 (RA) and 8.1. (redirect): Mitigates CVE-2016-3698. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* libndp: validate the IPv6 hop limitLubomir Rintel2016-05-171-11/+40
| | | | | | | | | | | | | | | None of the NDP messages should ever come from a non-local network; as stated in RFC4861's 6.1.1 (RS), 6.1.2 (RA), 7.1.1 (NS), 7.1.2 (NA), and 8.1. (redirect): - The IP Hop Limit field has a value of 255, i.e., the packet could not possibly have been forwarded by a router. This fixes CVE-2016-3698. Reported by: Julien BERNARD <julien.bernard@viagenie.ca> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* libndp: revert API change for ndp_msg_send() and add ndp_msg_send_with_flags()Thomas Haller2016-03-101-1/+16
| | | | | | Fixes: cb1ab5fc8b ("libndp: add option flags to send messages") Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* libndp: fix type of field "na" in "struct ndp_msgna"Thomas Haller2016-03-101-1/+1
| | | | | | | | | | | | Otherwise, compilation fails since commit cb1ab5fc8b: libndp.c: In function ‘ndp_msgna_flag_router’: libndp.c:992:18: error: ‘struct nd_neighbor_solicit’ has no member named ‘nd_na_hdr’ return msgna->na->nd_na_flags_reserved & ND_NA_FLAG_ROUTER; Fixes: dfed476eee ("lib: setup first pointer in all type-specific structures at once") Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* libndp: add option flags to send messagesJamie Bainbridge2016-03-101-2/+112
| | | | | | | | | | | | Within NA and RA message types, there are flags such as Solicited and Override (RFC-4861 Section 4). RA flags are currently implemented but not NA flags, so add remaining NA flag getters/setters. Set Solicited/Override flag on NA when appropriate, add a flags interface to the send API, and implement ability to send Unsolicited NA. Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
* update copyright datesJiri Pirko2015-04-023-3/+3
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* libndp: fix buffer overflow in ndp_msg_opt_dnssl_domain()Andrew Ayer2014-07-291-6/+9
| | | | | | | | | | | The buf array would overflow when processing a malformed DNSSL option containing a domain name whose labels' combined length exceeded 255 bytes. To facilitate the bounds checking, the code has been restructured slightly to be simpler and avoid repeated calls to strlen and strcat. Signed-off-by: Andrew Ayer <agwa@andrewayer.name> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* libndp: fix [cppcheck] Undefined behavior: Variable 'buf' is used as ↵Jiri Pirko2013-12-181-1/+1
| | | | | | | | | | | | | | | | | | | | parameter and destination in s[n]printf() cppcheck --enable=all --inconclusive --std=posix . ndp_msg_opt_dnssl_domain(): if (dom_len > len) return NULL; if (strlen(buf)) ----> sprintf(buf, "%s.", buf); buf[strlen(buf) + dom_len] = '\0'; memcpy(buf + strlen(buf), ptr, dom_len); So just use strcat instead. Reported-by: Dan Williams <dcbw@redhat.com> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* libndp: silently ignore packets with optlen 0Jiri Pirko2013-10-071-3/+10
| | | | | | as RFC 2461 requires. Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* libndp: fix processing for larger optionsJiri Pirko2013-10-071-2/+2
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* libndp: do not fail on receiving non-ndp packetsJiri Pirko2013-10-071-1/+3
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* fix cflags path in pc fileJiri Pirko2013-08-161-1/+1
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* add flag getters for prefix optionJiri Pirko2013-06-131-0/+60
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* libndp: allow mysendto6() to fail when iface is down and for other errorsJiri Pirko2013-06-071-5/+0
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* libndp: add ndp_callall_eventfd_handler()Jiri Pirko2013-06-071-0/+34
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* fix compile error on ia32Jiri Pirko2013-05-041-1/+1
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* add missing list.h into Makefile.amJiri Pirko2013-04-171-1/+1
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* add support for DNS Search List (rfc6106)Jiri Pirko2013-04-172-0/+89
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: add missing offset arg commentJiri Pirko2013-04-121-0/+14
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* add support for Recursive DNS Server (rfc6106)Jiri Pirko2013-04-122-0/+61
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: introcude option validity check callback for separate option typesJiri Pirko2013-04-051-2/+17
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: move msg validity check into separate functionJiri Pirko2013-04-051-4/+15
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: introduce option validity checksJiri Pirko2013-04-051-0/+47
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: remove unused fields from RA structJiri Pirko2013-04-051-22/+0
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* add support for Default Router Preference in RA msg (rfc4191)Jiri Pirko2013-04-051-0/+39
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* add support for Route Information Option (rfc4191)Jiri Pirko2013-04-052-3/+97
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: set addr in myrecvfrom6Jiri Pirko2013-04-051-0/+1
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* libndp: remove unnecessary evenfd struct and handle all by single event fdJiri Pirko2013-03-291-40/+5
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* libndp: change the was opts are handledJiri Pirko2013-03-291-438/+444
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: init msg->len accorsding to ND type during init and introduce maxlen getterJiri Pirko2013-03-171-6/+21
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: adjust destination address before send for certain ND typesJiri Pirko2013-03-171-0/+31
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: add forgotten p_msg assign in ndp_msg_newJiri Pirko2013-03-171-0/+1
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: add msg ifindex setterJiri Pirko2013-03-171-0/+12
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: add support for sending ND messagesJiri Pirko2013-03-171-0/+52
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: remove local ifindex variable in ndp_sock_recvJiri Pirko2013-03-171-4/+3
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: pass on flags in recvfromJiri Pirko2013-03-171-1/+1
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: use in6_addr instead od sockaddr_in6 in function paramsJiri Pirko2013-03-171-19/+11
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: setup first pointer in all type-specific structures at onceJiri Pirko2013-03-171-3/+15
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: remove msg->type and rather use in header valueJiri Pirko2013-03-171-4/+18
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: get rid of ndp_process_* functionsJiri Pirko2013-03-171-68/+24
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>
* lib: move len check into ndp_sock_recvJiri Pirko2013-03-171-4/+4
| | | | Signed-off-by: Jiri Pirko <jiri@resnulli.us>