1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <sys/stat.h>
5 
6 #include "sd-netlink.h"
7 
8 #include "in-addr-util.h"
9 #include "network-util.h"
10 #include "ratelimit.h"
11 #include "resolve-util.h"
12 
13 typedef struct Link Link;
14 typedef struct LinkAddress LinkAddress;
15 
16 #include "resolved-dns-rr.h"
17 #include "resolved-dns-scope.h"
18 #include "resolved-dns-search-domain.h"
19 #include "resolved-dns-server.h"
20 
21 #define LINK_SEARCH_DOMAINS_MAX 256
22 #define LINK_DNS_SERVERS_MAX 256
23 
24 struct LinkAddress {
25         Link *link;
26 
27         int family;
28         union in_addr_union in_addr;
29         unsigned char prefixlen;
30 
31         unsigned char flags, scope;
32 
33         DnsResourceRecord *llmnr_address_rr;
34         DnsResourceRecord *llmnr_ptr_rr;
35         DnsResourceRecord *mdns_address_rr;
36         DnsResourceRecord *mdns_ptr_rr;
37 
38         LIST_FIELDS(LinkAddress, addresses);
39 };
40 
41 struct Link {
42         Manager *manager;
43 
44         int ifindex;
45         unsigned flags;
46 
47         LIST_HEAD(LinkAddress, addresses);
48         unsigned n_addresses;
49 
50         LIST_HEAD(DnsServer, dns_servers);
51         DnsServer *current_dns_server;
52         unsigned n_dns_servers;
53 
54         LIST_HEAD(DnsSearchDomain, search_domains);
55         unsigned n_search_domains;
56 
57         int default_route;
58 
59         ResolveSupport llmnr_support;
60         ResolveSupport mdns_support;
61         DnsOverTlsMode dns_over_tls_mode;
62         DnssecMode dnssec_mode;
63         Set *dnssec_negative_trust_anchors;
64 
65         DnsScope *unicast_scope;
66         DnsScope *llmnr_ipv4_scope;
67         DnsScope *llmnr_ipv6_scope;
68         DnsScope *mdns_ipv4_scope;
69         DnsScope *mdns_ipv6_scope;
70 
71         struct stat networkd_state_file_stat;
72         LinkOperationalState networkd_operstate;
73         bool is_managed;
74 
75         char *ifname;
76         uint32_t mtu;
77         uint8_t operstate;
78 
79         bool loaded;
80         char *state_file;
81 
82         bool unicast_relevant;
83 };
84 
85 int link_new(Manager *m, Link **ret, int ifindex);
86 Link *link_free(Link *l);
87 int link_process_rtnl(Link *l, sd_netlink_message *m);
88 int link_update(Link *l);
89 bool link_relevant(Link *l, int family, bool local_multicast);
90 LinkAddress* link_find_address(Link *l, int family, const union in_addr_union *in_addr);
91 void link_add_rrs(Link *l, bool force_remove);
92 
93 void link_flush_settings(Link *l);
94 void link_set_dnssec_mode(Link *l, DnssecMode mode);
95 void link_set_dns_over_tls_mode(Link *l, DnsOverTlsMode mode);
96 void link_allocate_scopes(Link *l);
97 
98 DnsServer* link_set_dns_server(Link *l, DnsServer *s);
99 DnsServer* link_get_dns_server(Link *l);
100 void link_next_dns_server(Link *l, DnsServer *if_current);
101 
102 DnssecMode link_get_dnssec_mode(Link *l);
103 bool link_dnssec_supported(Link *l);
104 
105 DnsOverTlsMode link_get_dns_over_tls_mode(Link *l);
106 
107 int link_save_user(Link *l);
108 int link_load_user(Link *l);
109 void link_remove_user(Link *l);
110 
111 int link_address_new(Link *l, LinkAddress **ret, int family, const union in_addr_union *in_addr);
112 LinkAddress *link_address_free(LinkAddress *a);
113 int link_address_update_rtnl(LinkAddress *a, sd_netlink_message *m);
114 bool link_address_relevant(LinkAddress *l, bool local_multicast);
115 void link_address_add_rrs(LinkAddress *a, bool force_remove);
116 
117 bool link_negative_trust_anchor_lookup(Link *l, const char *name);
118 
119 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
120