Lines Matching +full:bl +full:- +full:data +full:- +full:offset

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 #include <atf-c.h>
92 if (s == -1) in _check_cloner()
158 ifname[strlen(ifname) - 1] = 'b'; in iface_create()
193 if (fd == -1) { in iface_open()
195 return (-1); in iface_open()
236 snprintf(cmd, sizeof(cmd), "/sbin/ifconfig %s -alias %s", ifname, addr); in iface_delete_addr()
250 return (-1); in iface_turn_up()
256 return (-1); in iface_turn_up()
263 return (-1); in iface_turn_up()
288 return (-1); in iface_enable_ipv6()
295 return (-1); in iface_enable_ipv6()
321 snprintf(cmd, sizeof(cmd), "/usr/sbin/jexec %s /sbin/ifconfig -l", vnet_name); in vnet_wait_interface()
327 line[strlen(line)-1] = '\0'; in vnet_wait_interface()
349 "/usr/sbin/jail -i -c name=%s persist vnet", vnet_name); in vnet_switch()
351 len += snprintf(&cmd[len], sizeof(cmd) - len, in vnet_switch()
378 if (jail_attach(jid) == -1) { in vnet_switch()
405 const struct sockaddr_dl *al, *bl; in sa_equal_msg_flags() local
416 if (a->sa_family != b->sa_family) { in sa_equal_msg_flags()
417 snprintf(msg, sz, "family: %d vs %d", a->sa_family, b->sa_family); in sa_equal_msg_flags()
420 if (a->sa_len != b->sa_len) { in sa_equal_msg_flags()
421 snprintf(msg, sz, "len: %d vs %d", a->sa_len, b->sa_len); in sa_equal_msg_flags()
425 switch (a->sa_family) { in sa_equal_msg_flags()
429 if (a4->sin_addr.s_addr != b4->sin_addr.s_addr) { in sa_equal_msg_flags()
430 inet_ntop(AF_INET, &a4->sin_addr, a_s, sizeof(a_s)); in sa_equal_msg_flags()
431 inet_ntop(AF_INET, &b4->sin_addr, b_s, sizeof(b_s)); in sa_equal_msg_flags()
435 if (a4->sin_port != b4->sin_port) { in sa_equal_msg_flags()
437 ntohs(a4->sin_port), ntohs(b4->sin_port)); in sa_equal_msg_flags()
441 a32 = (const uint32_t *)a4->sin_zero; in sa_equal_msg_flags()
442 b32 = (const uint32_t *)b4->sin_zero; in sa_equal_msg_flags()
453 if (!IN6_ARE_ADDR_EQUAL(&a6->sin6_addr, &b6->sin6_addr)) { in sa_equal_msg_flags()
454 inet_ntop(AF_INET6, &a6->sin6_addr, a_s, sizeof(a_s)); in sa_equal_msg_flags()
455 inet_ntop(AF_INET6, &b6->sin6_addr, b_s, sizeof(b_s)); in sa_equal_msg_flags()
459 if (a6->sin6_scope_id != b6->sin6_scope_id) { in sa_equal_msg_flags()
460 snprintf(msg, sz, "scope diff: %u vs %u", a6->sin6_scope_id, b6->sin6_scope_id); in sa_equal_msg_flags()
466 bl = (const struct sockaddr_dl *)b; in sa_equal_msg_flags()
468 if (al->sdl_index != bl->sdl_index) { in sa_equal_msg_flags()
469 snprintf(msg, sz, "sdl_index diff: %u vs %u", al->sdl_index, bl->sdl_index); in sa_equal_msg_flags()
473 if ((al->sdl_alen != bl->sdl_alen) || (memcmp(LLADDR(al), LLADDR(bl), al->sdl_alen) != 0)) { in sa_equal_msg_flags()
475 sa_print_hd(abuf, sizeof(abuf), LLADDR(al), al->sdl_alen); in sa_equal_msg_flags()
476 sa_print_hd(bbuf, sizeof(bbuf), LLADDR(bl), bl->sdl_alen); in sa_equal_msg_flags()
478 abuf, al->sdl_alen, bbuf, bl->sdl_alen); in sa_equal_msg_flags()
482 if (((flags & SA_F_IGNORE_IFTYPE) == 0) && (al->sdl_type != bl->sdl_type)) { in sa_equal_msg_flags()
483 snprintf(msg, sz, "sdl_type diff: %u vs %u", al->sdl_type, bl->sdl_type); in sa_equal_msg_flags()
487 if (((flags & SA_F_IGNORE_IFNAME) == 0) && ((al->sdl_nlen != bl->sdl_nlen) || in sa_equal_msg_flags()
488 (memcmp(al->sdl_data, bl->sdl_data, al->sdl_nlen) != 0))) { in sa_equal_msg_flags()
490 memcpy(abuf, al->sdl_data, al->sdl_nlen); in sa_equal_msg_flags()
491 abuf[al->sdl_nlen] = '\0'; in sa_equal_msg_flags()
492 memcpy(bbuf, bl->sdl_data, bl->sdl_nlen); in sa_equal_msg_flags()
493 abuf[bl->sdl_nlen] = '\0'; in sa_equal_msg_flags()
495 abuf, al->sdl_nlen, bbuf, bl->sdl_nlen); in sa_equal_msg_flags()
504 if (memcmp(a, b, a->sa_len)) { in sa_equal_msg_flags()
506 for (i = 0; i < a->sa_len; i++) in sa_equal_msg_flags()
513 snprintf(msg, sz, "overall memcmp() reports diff for af %d offset %d", in sa_equal_msg_flags()
514 a->sa_family, i); in sa_equal_msg_flags()
532 sin->sin_family = AF_INET; in sa_fill_mask4()
533 sin->sin_len = sizeof(struct sockaddr_in); in sa_fill_mask4()
534 sin->sin_addr.s_addr = htonl(plen ? ~((1 << (32 - plen)) - 1) : 0); in sa_fill_mask4()
543 sin6->sin6_family = AF_INET6; in sa_fill_mask6()
544 sin6->sin6_len = sizeof(struct sockaddr_in6); in sa_fill_mask6()
546 for (cp = (uint32_t *)&sin6->sin6_addr; mask >= 32; mask -= 32) in sa_fill_mask6()
549 *cp = htonl(mask ? ~((1 << (32 - mask)) - 1) : 0); in sa_fill_mask6()
577 if (k != NULL && (k - addr) <= ETHER_MAC_MAX_LENGTH) in sa_convert_str_to_sa()
600 sin6->sin6_family = AF_INET6; in sa_convert_str_to_sa()
601 sin6->sin6_len = sizeof(struct sockaddr_in6); in sa_convert_str_to_sa()
602 sin6->sin6_scope_id = ifindex; in sa_convert_str_to_sa()
603 error = inet_pton(AF_INET6, addr, &sin6->sin6_addr); in sa_convert_str_to_sa()
611 sin->sin_family = AF_INET; in sa_convert_str_to_sa()
612 sin->sin_len = sizeof(struct sockaddr_in); in sa_convert_str_to_sa()
613 error = inet_pton(AF_INET, addr, &sin->sin_addr); in sa_convert_str_to_sa()
621 sdl->sdl_family = AF_LINK; in sa_convert_str_to_sa()
622 sdl->sdl_len = sizeof(struct sockaddr_dl); in sa_convert_str_to_sa()
623 sdl->sdl_index = ifindex; in sa_convert_str_to_sa()
624 sdl->sdl_alen = 6; in sa_convert_str_to_sa()
643 ATF_REQUIRE_MSG(fd != -1, "rtsock open failed: %s", strerror(errno)); in rtsock_setup_socket()
661 len = write(fd, rtm, rtm->rtm_msglen); in rtsock_send_rtm()
663 RTSOCK_ATF_REQUIRE_MSG(rtm, len == rtm->rtm_msglen, in rtsock_send_rtm()
665 rtm->rtm_msglen, len, strerror(my_errno)); in rtsock_send_rtm()
677 /* Check for the data available to read first */ in rtsock_read_rtm()
702 if (rtm->rtm_pid == getpid() && rtm->rtm_seq == seq) in rtsock_read_rtm_reply()
705 RLOG("--- MATCHED RTSOCK MESSAGE ---"); in rtsock_read_rtm_reply()
707 RLOG("--- SKIPPED RTSOCK MESSAGE ---"); in rtsock_read_rtm_reply()
721 rtm->rtm_type = cmd; in rtsock_prepare_route_message_base()
722 rtm->rtm_version = RTM_VERSION; in rtsock_prepare_route_message_base()
723 rtm->rtm_seq = _rtm_seq++; in rtsock_prepare_route_message_base()
737 rtm->rtm_flags |= RTF_GATEWAY; in rtsock_prepare_route_message()
749 if (rtm->rtm_addrs & (1 << i)) { in rtsock_add_rtm_sa()
751 ptr += ALIGN(((struct sockaddr *)ptr)->sa_len); in rtsock_add_rtm_sa()
755 rtm->rtm_addrs |= addr_type; in rtsock_add_rtm_sa()
756 memcpy(ptr, sa, sa->sa_len); in rtsock_add_rtm_sa()
764 if (rtm->rtm_addrs & (1 << i)) { in rtsock_find_rtm_sa()
768 ptr += ALIGN(((struct sockaddr *)ptr)->sa_len); in rtsock_find_rtm_sa()
782 if (rtm->rtm_addrs & (1 << i)) { in rtsock_calc_rtm_len()
784 int sa_len = ALIGN(((struct sockaddr *)ptr)->sa_len); in rtsock_calc_rtm_len()
797 rtm->rtm_msglen = rtsock_calc_rtm_len(rtm); in rtsock_update_rtm_len()
801 _validate_message_sockaddrs(char *buffer, int rtm_len, size_t offset, int rtm_addrs) in _validate_message_sockaddrs() argument
804 size_t parsed_len = offset; in _validate_message_sockaddrs()
806 /* Offset denotes initial header size */ in _validate_message_sockaddrs()
807 sa = (struct sockaddr *)(buffer + offset); in _validate_message_sockaddrs()
814 "SA %d: len %d exceeds msg size %d", i, (int)sa->sa_len, rtm_len); in _validate_message_sockaddrs()
815 if (sa->sa_family == AF_LINK) { in _validate_message_sockaddrs()
817 int data_len = sdl->sdl_nlen + sdl->sdl_alen; in _validate_message_sockaddrs()
822 "AF_LINK data size exceeds total len: %u vs %u, nlen=%d alen=%d", in _validate_message_sockaddrs()
823 data_len, rtm_len, sdl->sdl_nlen, sdl->sdl_alen); in _validate_message_sockaddrs()
840 ATF_REQUIRE_MSG(rtm->rtm_version == RTM_VERSION, "unknown RTM_VERSION: expected %d got %d", in rtsock_validate_message()
841 RTM_VERSION, rtm->rtm_version); in rtsock_validate_message()
842 ATF_REQUIRE_MSG(rtm->rtm_msglen <= len, "wrong message length: expected %d got %d", in rtsock_validate_message()
843 (int)len, (int)rtm->rtm_msglen); in rtsock_validate_message()
845 switch (rtm->rtm_type) { in rtsock_validate_message()
850 _validate_message_sockaddrs(buffer, rtm->rtm_msglen, in rtsock_validate_message()
851 sizeof(struct rt_msghdr), rtm->rtm_addrs); in rtsock_validate_message()
855 _validate_message_sockaddrs(buffer, rtm->rtm_msglen, in rtsock_validate_message()
856 sizeof(struct ifa_msghdr), ((struct ifa_msghdr *)buffer)->ifam_addrs); in rtsock_validate_message()
864 RTSOCK_ATF_REQUIRE_MSG(rtm, rtm->rtm_pid == getpid(), "expected pid %d, got %d", in rtsock_validate_pid_ours()
865 getpid(), rtm->rtm_pid); in rtsock_validate_pid_ours()
871 RTSOCK_ATF_REQUIRE_MSG(rtm, rtm->rtm_pid > 0, "expected non-zero pid, got %d", in rtsock_validate_pid_user()
872 rtm->rtm_pid); in rtsock_validate_pid_user()
878 RTSOCK_ATF_REQUIRE_MSG(rtm, rtm->rtm_pid == 0, "expected zero pid, got %d", in rtsock_validate_pid_kernel()
879 rtm->rtm_pid); in rtsock_validate_pid_kernel()