Debian Codegraph @

src/network/networkd-nexthop.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later
2 * Copyright © 2019 VMware, Inc.
3 */
4
5 #pragma once
6
7 #include "in-addr-util.h"
8 #include "networkd-forward.h"
9 #include "networkd-util.h"
10
11 typedef int (*nexthop_netlink_handler_t)(
12 sd_netlink *rtnl,
13 sd_netlink_message *m,
14 Request *req,
15 Link *link,
16 NextHop *nexthop);
17
18 typedef struct NextHop {
19 Network *network;
20 Manager *manager;
21 ConfigSection *section;
22 NetworkConfigSource source;
23 NetworkConfigState state;
24 union in_addr_union provider; /* DHCP server or router address */
25
26 unsigned n_ref;
27
28 /* struct nhmsg */
29 int family;
30 uint8_t protocol;
31 uint32_t flags;
32
33 /* attributes */
34 uint32_t id; /* NHA_ID */
35 Hashmap *group; /* NHA_GROUP */
36 bool blackhole; /* NHA_BLACKHOLE */
37 int ifindex; /* NHA_OIF */
38 struct in_addr_data gw; /* NHA_GATEWAY, gw.family is only used by conf parser. */
39
40 /* Only used in conf parser and nexthop_section_verify(). */
41 int onlink;
42
43 /* For managing routes and nexthops that depend on this nexthop. */
44 Set *nexthops;
45 Set *routes;
46 } NextHop;
47
48 void log_nexthop_debug(const NextHop *nexthop, const char *str, Manager *manager);
49
50 int nexthop_new(NextHop **ret);
51 NextHop* nexthop_ref(NextHop *nexthop);
52 NextHop* nexthop_unref(NextHop *nexthop);
53 DEFINE_SECTION_CLEANUP_FUNCTIONS(NextHop, nexthop_unref);
54
55 int nexthop_remove(NextHop *nexthop, Manager *manager);
56 int nexthop_remove_and_cancel(NextHop *nexthop, Manager *manager);
57
58 int network_drop_invalid_nexthops(Network *network);
59
60 int link_drop_nexthops(Link *link, bool only_static);
61 static inline int link_drop_unmanaged_nexthops(Link *link) {
62 return link_drop_nexthops(link, /* only_static= */ false);
63 }
64 static inline int link_drop_static_nexthops(Link *link) {
65 return link_drop_nexthops(link, /* only_static= */ true);
66 }
67 void link_forget_nexthops(Link *link);
68
69 int nexthop_configure_handler_internal(sd_netlink_message *m, Link *link, NextHop *nexthop);
70 int link_request_nexthop(
71 Link *link,
72 const NextHop *nexthop,
73 unsigned *message_counter,
74 nexthop_netlink_handler_t netlink_handler);
75 int link_request_static_nexthops(Link *link, bool only_ipv4);
76
77 int nexthop_get_by_id(Manager *manager, uint32_t id, NextHop **ret);
78 int nexthop_get_request_by_id(Manager *manager, uint32_t id, Request **ret);
79 int nexthop_is_ready(Manager *manager, uint32_t id, NextHop **ret);
80 int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
81 int manager_build_nexthop_ids(Manager *manager);
82
83 DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(NextHop, nexthop);
84
85 typedef enum NextHopConfParserType {
86 NEXTHOP_ID,
87 NEXTHOP_GATEWAY,
88 NEXTHOP_FAMILY,
89 NEXTHOP_ONLINK,
90 NEXTHOP_BLACKHOLE,
91 NEXTHOP_GROUP,
92 _NEXTHOP_CONF_PARSER_MAX,
93 _NEXTHOP_CONF_PARSER_INVALID = -EINVAL,
94 } NextHopConfParserType;
95
96 CONFIG_PARSER_PROTOTYPE(config_parse_nexthop_section);