From a7b214a88b6284801636ba70d3631d067ff93976 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Mar 14 2021 14:41:16 +0000 Subject: Prepare for a new update Reverting patches so we can apply the latest update and changes can be seen in the spec file and sources. --- diff --git a/include/ndp.h b/include/ndp.h index 7bf8794..0dc1468 100644 --- a/include/ndp.h +++ b/include/ndp.h @@ -79,9 +79,6 @@ enum ndp_msg_type ndp_msg_type(struct ndp_msg *msg); struct in6_addr *ndp_msg_addrto(struct ndp_msg *msg); uint32_t ndp_msg_ifindex(struct ndp_msg *msg); void ndp_msg_ifindex_set(struct ndp_msg *msg, uint32_t ifindex); -void ndp_msg_target_set(struct ndp_msg *msg, struct in6_addr *target); -void ndp_msg_dest_set(struct ndp_msg *msg, struct in6_addr *dest); -void ndp_msg_opt_set(struct ndp_msg *msg); int ndp_msg_send(struct ndp *ndp, struct ndp_msg *msg); int ndp_msg_send_with_flags(struct ndp *ndp, struct ndp_msg *msg, uint8_t flags); diff --git a/libndp/libndp.c b/libndp/libndp.c index 283de77..baacb76 100644 --- a/libndp/libndp.c +++ b/libndp/libndp.c @@ -32,14 +32,10 @@ #include #include #include -#include -#include #include "ndp_private.h" #include "list.h" -#define pr_err(args...) fprintf(stderr, ##args) - /** * SECTION: logging * @short_description: libndp logging facility @@ -312,18 +308,6 @@ static void ndp_msg_addrto_adjust_all_routers(struct in6_addr *addr) addr->s6_addr32[3] = htonl(0x2); } -/* - * compute link-local solicited-node multicast address - */ -static void ndp_msg_addrto_adjust_solicit_multi(struct in6_addr *addr, - struct in6_addr *target) -{ - addr->s6_addr32[0] = htonl(0xFF020000); - addr->s6_addr32[1] = 0; - addr->s6_addr32[2] = htonl(0x1); - addr->s6_addr32[3] = htonl(0xFF000000) | target->s6_addr32[3]; -} - static bool ndp_msg_addrto_validate_link_local(struct in6_addr *addr) { return IN6_IS_ADDR_LINKLOCAL (addr); @@ -696,137 +680,6 @@ void ndp_msg_ifindex_set(struct ndp_msg *msg, uint32_t ifindex) } /** - * ndp_msg_dest_set: - * @msg: message structure - * @dest: ns,na dest - * - * Set dest address in IPv6 header for NS and NA. - **/ -NDP_EXPORT -void ndp_msg_dest_set(struct ndp_msg *msg, struct in6_addr *dest) -{ - enum ndp_msg_type msg_type = ndp_msg_type(msg); - switch (msg_type) { - case NDP_MSG_NS: - /* fall through */ - case NDP_MSG_NA: - msg->addrto = *dest; - /* fall through */ - default: - break; - } -} - -/** - * ndp_msg_target_set: - * @msg: message structure - * @target: ns,na target - * - * Set target address in ICMPv6 header for NS and NA. - **/ -NDP_EXPORT -void ndp_msg_target_set(struct ndp_msg *msg, struct in6_addr *target) -{ - struct in6_addr any = IN6ADDR_ANY_INIT; - enum ndp_msg_type msg_type = ndp_msg_type(msg); - - switch (msg_type) { - case NDP_MSG_NS: - ((struct ndp_msgns*)&msg->nd_msg)->ns->nd_ns_target = *target; - /* - * Neighbor Solicitations are multicast when the node - * needs to resolve an address and unicast when the - * node seeks to verify the reachability of a - * neighbor. - * - * In this case we need to update the dest address in - * IPv6 header when - * a) IPv6 dest address is not set - * b) ICMPv6 target address is supplied - * */ - if (!memcmp(&msg->addrto, &any, sizeof(any)) && - memcmp(target, &any, sizeof(any))) - ndp_msg_addrto_adjust_solicit_multi(&msg->addrto, target); - break; - case NDP_MSG_NA: - ((struct ndp_msgna*)&msg->nd_msg)->na->nd_na_target = *target; - break; - default: - break; - } -} - -static int ndp_get_iface_mac(int ifindex, char *ptr) -{ - int sockfd, err = 0; - struct ifreq ifr; - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd == -1) { - pr_err("%s: Failed to create socket", __func__); - return -errno; - } - - if (if_indextoname(ifindex, (char *)&ifr.ifr_name) == NULL) { - pr_err("%s: Failed to get iface name with index %d", __func__, ifindex); - err = -errno; - goto close_sock; - } - - if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) { - pr_err("%s: Failed to get iface mac with index %d\n", __func__, ifindex); - err = -errno; - goto close_sock; - } - - memcpy(ptr, &ifr.ifr_hwaddr.sa_data, sizeof(ifr.ifr_hwaddr.sa_data)); - -close_sock: - close(sockfd); - return err; -} - -static void ndp_msg_opt_set_linkaddr(struct ndp_msg *msg, int ndp_opt) -{ - char *opts_start = ndp_msg_payload_opts(msg); - struct nd_opt_hdr *s_laddr_opt = (struct nd_opt_hdr *) opts_start; - char *opt_data = (char *) s_laddr_opt + sizeof(struct nd_opt_hdr); - int err; - - err = ndp_get_iface_mac(ndp_msg_ifindex(msg), opt_data); - if (err) - return; - - opt_data += 6; - s_laddr_opt->nd_opt_type = ndp_opt; - s_laddr_opt->nd_opt_len = (opt_data - opts_start) >> 3; - msg->len += opt_data - opts_start; -} - -/** - * ndp_msg_opt_set: - * @msg: message structure - * - * Set neighbor discovery option info. - **/ -NDP_EXPORT -void ndp_msg_opt_set(struct ndp_msg *msg) -{ - enum ndp_msg_type msg_type = ndp_msg_type(msg); - - switch (msg_type) { - case NDP_MSG_NS: - ndp_msg_opt_set_linkaddr(msg, ND_OPT_SOURCE_LINKADDR); - break; - case NDP_MSG_NA: - ndp_msg_opt_set_linkaddr(msg, ND_OPT_TARGET_LINKADDR); - break; - default: - break; - } -} - -/** * ndp_msg_send: * @ndp: libndp library context * @msg: message structure diff --git a/man/ndptool.8 b/man/ndptool.8 index fb0dd63..ef765dc 100644 --- a/man/ndptool.8 +++ b/man/ndptool.8 @@ -42,14 +42,6 @@ Neighbor Advertisement. Specified interface name. .TP -.B "\-D dest, \-\-dest dest" -Specified dest address in IPv6 header for NS/NA message. - -.TP -.B "\-T target, \-\-target target" -Specified target address in ICMPv6 header for NS/NA message. - -.TP .B "\-U, \-\-unsolicited" Send Unsolicited NA. diff --git a/utils/ndptool.c b/utils/ndptool.c index 4eca83d..96479fa 100644 --- a/utils/ndptool.c +++ b/utils/ndptool.c @@ -135,8 +135,6 @@ static void print_help(const char *argv0) { "\t-v --verbose Increase output verbosity\n" "\t-t --msg-type=TYPE Specify message type\n" "\t (\"rs\", \"ra\", \"ns\", \"na\")\n" - "\t-D --dest=DEST Dest address in IPv6 header for NS or NA\n" - "\t-T --target=TARGET Target address in ICMPv6 header for NS or NA\n" "\t-i --ifname=IFNAME Specify interface name\n" "\t-U --unsolicited Send Unsolicited NA\n" "Available commands:\n" @@ -335,8 +333,7 @@ static int run_cmd_monitor(struct ndp *ndp, enum ndp_msg_type msg_type, } static int run_cmd_send(struct ndp *ndp, enum ndp_msg_type msg_type, - uint32_t ifindex, struct in6_addr *dest, - struct in6_addr *target) + uint32_t ifindex) { struct ndp_msg *msg; int err; @@ -347,9 +344,6 @@ static int run_cmd_send(struct ndp *ndp, enum ndp_msg_type msg_type, return err; } ndp_msg_ifindex_set(msg, ifindex); - ndp_msg_dest_set(msg, dest); - ndp_msg_target_set(msg, target); - ndp_msg_opt_set(msg); err = ndp_msg_send_with_flags(ndp, msg, flags); if (err) { @@ -390,34 +384,26 @@ int main(int argc, char **argv) { "verbose", no_argument, NULL, 'v' }, { "msg-type", required_argument, NULL, 't' }, { "ifname", required_argument, NULL, 'i' }, - { "dest", required_argument, NULL, 'D' }, - { "target", required_argument, NULL, 'T' }, { "unsolicited",no_argument, NULL, 'U' }, { NULL, 0, NULL, 0 } }; - - struct in6_addr target = IN6ADDR_ANY_INIT; - struct in6_addr dest = IN6ADDR_ANY_INIT; - enum ndp_msg_type msg_type; + int opt; + struct ndp *ndp; char *msgtypestr = NULL; - int res = EXIT_FAILURE; + enum ndp_msg_type msg_type; char *ifname = NULL; - char *daddr = NULL; - char *taddr = NULL; uint32_t ifindex; - struct ndp *ndp; char *cmd_name; - int opt; int err; + int res = EXIT_FAILURE; - while ((opt = getopt_long(argc, argv, "hvt:D:T:i:U", + while ((opt = getopt_long(argc, argv, "hvt:i:U", long_options, NULL)) >= 0) { switch(opt) { case 'h': print_help(argv0); - res = EXIT_SUCCESS; - goto errout; + return EXIT_SUCCESS; case 'v': g_verbosity++; break; @@ -429,25 +415,17 @@ int main(int argc, char **argv) free(ifname); ifname = strdup(optarg); break; - case 'D': - free(daddr); - daddr = strdup(optarg); - break; - case 'T': - free(taddr); - taddr = strdup(optarg); - break; case 'U': flags |= ND_OPT_NA_UNSOL; break; case '?': pr_err("unknown option.\n"); print_help(argv0); - goto errout; + return EXIT_FAILURE; default: pr_err("unknown option \"%c\".\n", opt); print_help(argv0); - goto errout; + return EXIT_FAILURE; } } @@ -470,21 +448,6 @@ int main(int argc, char **argv) } } - if (daddr && (flags & ND_OPT_NA_UNSOL)) { - pr_err("Conflicts for both setting dest address and unsolicited flag\n"); - goto errout; - } - - if (daddr && inet_pton(AF_INET6, daddr, &dest) <= 0) { - pr_err("Invalid dest address \"%s\"\n", daddr); - goto errout; - } - - if (taddr && inet_pton(AF_INET6, taddr, &target) <= 0) { - pr_err("Invalid target address \"%s\"\n", taddr); - goto errout; - } - err = get_msg_type(&msg_type, msgtypestr); if (err) { pr_err("Invalid message type \"%s\" selected\n", msgtypestr); @@ -515,7 +478,7 @@ int main(int argc, char **argv) print_help(argv0); goto errout; } - err = run_cmd_send(ndp, msg_type, ifindex, &dest, &target); + err = run_cmd_send(ndp, msg_type, ifindex); } else { pr_err("Unknown command \"%s\"\n", cmd_name); goto ndp_close; @@ -531,9 +494,5 @@ int main(int argc, char **argv) ndp_close: ndp_close(ndp); errout: - free(msgtypestr); - free(ifname); - free(daddr); - free(taddr); return res; }