Skip to content

Commit 4055e8f

Browse files
committed
Harden mdns runtime link handling
Fix Ubuntu CI portability by marking BSD-only ifreq parameters as intentionally unused on platforms that do not expose sockaddr lengths. Improve mdns-advertiser's runtime socket update path with rollback for partial multicast joins, IPv4 fallback when IPv6 transport setup fails, capacity truncation reporting, bounded stack-only log truncation, and known-answer suppression that does not hide other link-valid A/AAAA records. Rebuild mdns and nbns NetBSD artifacts and refresh the artifact manifest.
1 parent 1a8db58 commit 4055e8f

10 files changed

Lines changed: 1014 additions & 97 deletions

File tree

bin/mdns-netbsd4be/mdns-advertiser

3.07 KB
Binary file not shown.

bin/mdns-netbsd4le/mdns-advertiser

3.24 KB
Binary file not shown.

bin/mdns/mdns-advertiser

3.78 KB
Binary file not shown.

bin/nbns-netbsd4be/nbns-advertiser

8 Bytes
Binary file not shown.

bin/nbns-netbsd4le/nbns-advertiser

8 Bytes
Binary file not shown.

bin/nbns/nbns-advertiser

104 Bytes
Binary file not shown.

build/auto-ip-common.inc

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct iface_context {
2929
struct iface_context_set {
3030
struct iface_context contexts[MAX_IFACE_CONTEXTS];
3131
size_t count;
32+
int truncated;
3233
};
3334

3435
struct link_ipv4_addr {
@@ -47,6 +48,7 @@ struct link_context {
4748
char name[IFNAMSIZ];
4849
int flags;
4950
unsigned int ifindex;
51+
int mdns_ipv6_transport;
5052
struct link_ipv4_addr ipv4[MAX_LINK_IPV4_ADDRS];
5153
size_t ipv4_count;
5254
struct link_ipv6_addr ipv6[MAX_LINK_IPV6_ADDRS];
@@ -56,6 +58,7 @@ struct link_context {
5658
struct link_context_set {
5759
struct link_context links[MAX_IFACE_CONTEXTS];
5860
size_t count;
61+
int truncated;
5962
};
6063

6164
struct ifconf_entry_view {
@@ -127,6 +130,7 @@ static int TC_AUTO_IP_UNUSED ifreq_table_uses_fixed_entries(size_t ifc_len) {
127130
static size_t TC_AUTO_IP_UNUSED ifreq_sockaddr_len(const struct ifreq *ifr, size_t remaining) {
128131
size_t sockaddr_len = sizeof(struct sockaddr);
129132

133+
(void)ifr;
130134
if (remaining < IFNAMSIZ + sizeof(struct sockaddr)) {
131135
return 0;
132136
}
@@ -517,6 +521,7 @@ static int TC_AUTO_IP_UNUSED append_iface_context(struct iface_context_set *out,
517521
}
518522
}
519523
if (out->count >= MAX_IFACE_CONTEXTS) {
524+
out->truncated = 1;
520525
return 0;
521526
}
522527

@@ -733,6 +738,7 @@ static struct link_context TC_AUTO_IP_UNUSED *find_or_add_link_context(struct li
733738
}
734739
}
735740
if (out->count >= MAX_IFACE_CONTEXTS) {
741+
out->truncated = 1;
736742
return NULL;
737743
}
738744
ctx = &out->links[out->count++];
@@ -780,6 +786,7 @@ static int TC_AUTO_IP_UNUSED append_link_ipv4(struct link_context_set *out,
780786
return 0;
781787
}
782788
if (ctx->ipv4_count >= MAX_LINK_IPV4_ADDRS) {
789+
out->truncated = 1;
783790
return 0;
784791
}
785792
pos = ctx->ipv4_count++;
@@ -791,12 +798,13 @@ static int TC_AUTO_IP_UNUSED append_link_ipv4(struct link_context_set *out,
791798
return 1;
792799
}
793800

794-
static int TC_AUTO_IP_UNUSED append_link_ipv6(struct link_context_set *out,
795-
const char *name,
796-
const struct in6_addr *addr,
797-
int prefix_len,
798-
unsigned int scope_id,
799-
int flags) {
801+
static int TC_AUTO_IP_UNUSED append_link_ipv6_with_transport(struct link_context_set *out,
802+
const char *name,
803+
const struct in6_addr *addr,
804+
int prefix_len,
805+
unsigned int scope_id,
806+
int flags,
807+
int mdns_ipv6_transport) {
800808
struct link_context *ctx;
801809
size_t pos;
802810

@@ -808,11 +816,15 @@ static int TC_AUTO_IP_UNUSED append_link_ipv6(struct link_context_set *out,
808816
return 0;
809817
}
810818
if (ctx->ipv6_count >= MAX_LINK_IPV6_ADDRS) {
819+
out->truncated = 1;
811820
return 0;
812821
}
813822
if (ctx->ifindex == 0 && scope_id != 0) {
814823
ctx->ifindex = scope_id;
815824
}
825+
if (mdns_ipv6_transport) {
826+
ctx->mdns_ipv6_transport = 1;
827+
}
816828
pos = ctx->ipv6_count++;
817829
ctx->ipv6[pos].addr = *addr;
818830
ctx->ipv6[pos].scope_id = scope_id;
@@ -821,6 +833,15 @@ static int TC_AUTO_IP_UNUSED append_link_ipv6(struct link_context_set *out,
821833
return 1;
822834
}
823835

836+
static int TC_AUTO_IP_UNUSED append_link_ipv6(struct link_context_set *out,
837+
const char *name,
838+
const struct in6_addr *addr,
839+
int prefix_len,
840+
unsigned int scope_id,
841+
int flags) {
842+
return append_link_ipv6_with_transport(out, name, addr, prefix_len, scope_id, flags, 1);
843+
}
844+
824845
static int TC_AUTO_IP_UNUSED link_ipv6_addr_is_samba_bindable(const struct link_ipv6_addr *addr) {
825846
return addr->prefix_len >= 0 && runtime_ipv6_is_bindable(&addr->addr);
826847
}
@@ -860,7 +881,15 @@ static int TC_AUTO_IP_UNUSED link_context_has_advertisable_address(const struct
860881
}
861882

862883
static int TC_AUTO_IP_UNUSED link_context_has_mdns_ipv6_transport(const struct link_context *ctx) {
863-
return ctx->ifindex != 0 && ctx->ipv6_count > 0;
884+
return ctx->mdns_ipv6_transport && ctx->ifindex != 0 && ctx->ipv6_count > 0;
885+
}
886+
887+
static void TC_AUTO_IP_UNUSED disable_link_contexts_mdns_ipv6_transport(struct link_context_set *set) {
888+
size_t i;
889+
890+
for (i = 0; i < set->count; i++) {
891+
set->links[i].mdns_ipv6_transport = 0;
892+
}
864893
}
865894

866895
static int TC_AUTO_IP_UNUSED link_context_is_advertise_eligible(const struct link_context *ctx) {
@@ -877,6 +906,7 @@ static void TC_AUTO_IP_UNUSED filter_advertise_link_contexts(struct link_context
877906
continue;
878907
}
879908
if (out->count >= MAX_IFACE_CONTEXTS) {
909+
out->truncated = 1;
880910
break;
881911
}
882912
out->links[out->count++] = in->links[i];
@@ -891,6 +921,7 @@ static int TC_AUTO_IP_UNUSED link_context_identity_equal(const struct link_conte
891921
if (strcmp(a->name, b->name) != 0 ||
892922
a->flags != b->flags ||
893923
a->ifindex != b->ifindex ||
924+
a->mdns_ipv6_transport != b->mdns_ipv6_transport ||
894925
a->ipv4_count != b->ipv4_count ||
895926
a->ipv6_count != b->ipv6_count) {
896927
return 0;
@@ -1112,12 +1143,13 @@ static int TC_AUTO_IP_UNUSED collect_link_contexts_with_policy(struct link_conte
11121143
memset(&sin6, 0, sizeof(sin6));
11131144
memcpy(&sin6, entry.addr, sizeof(sin6));
11141145
prefix_len = get_ipv6_prefix_len(sockfd6, entry.name, &sin6);
1115-
append_link_ipv6(out,
1116-
entry.name,
1117-
&sin6.sin6_addr,
1118-
prefix_len,
1119-
(unsigned int)sin6.sin6_scope_id,
1120-
flags);
1146+
append_link_ipv6_with_transport(out,
1147+
entry.name,
1148+
&sin6.sin6_addr,
1149+
prefix_len,
1150+
(unsigned int)sin6.sin6_scope_id,
1151+
flags,
1152+
sockfd6 >= 0);
11211153
#if defined(AF_LINK) && (defined(__NetBSD__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
11221154
} else if (entry.addr->sa_family == AF_LINK && entry.addr_len >= sizeof(struct sockaddr_dl)) {
11231155
const struct sockaddr_dl *sdl = (const struct sockaddr_dl *)entry.addr;
@@ -1178,12 +1210,13 @@ static void TC_AUTO_IP_UNUSED log_link_contexts(const char *prefix, const struct
11781210
for (i = 0; i < set->count; i++) {
11791211
size_t j;
11801212
const struct link_context *ctx = &set->links[i];
1181-
fprintf(stderr, "%s: link[%lu] iface=%s flags=0x%x ifindex=%u score=%d ipv4=%lu ipv6=%lu\n",
1213+
fprintf(stderr, "%s: link[%lu] iface=%s flags=0x%x ifindex=%u mdns_ipv6=%d score=%d ipv4=%lu ipv6=%lu\n",
11821214
prefix,
11831215
(unsigned long)i,
11841216
ctx->name,
11851217
(unsigned int)ctx->flags,
11861218
ctx->ifindex,
1219+
ctx->mdns_ipv6_transport,
11871220
link_context_priority_score(ctx),
11881221
(unsigned long)ctx->ipv4_count,
11891222
(unsigned long)ctx->ipv6_count);

0 commit comments

Comments
 (0)