summary refs log tree commit diff
path: root/src/rdisc/nm-rdisc.h
blob: 9e5e9349bc76b1bf64e4321486ffe3917d1146d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-rdisc.h - Perform IPv6 router discovery
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Copyright (C) 2013 Red Hat, Inc.
 */

#ifndef __NETWORKMANAGER_RDISC_H__
#define __NETWORKMANAGER_RDISC_H__

#include <stdlib.h>
#include <netinet/in.h>

#include "nm-setting-ip6-config.h"
#include "NetworkManagerUtils.h"

#define NM_TYPE_RDISC            (nm_rdisc_get_type ())
#define NM_RDISC(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_RDISC, NMRDisc))
#define NM_RDISC_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_RDISC, NMRDiscClass))
#define NM_IS_RDISC(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_RDISC))
#define NM_IS_RDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_RDISC))
#define NM_RDISC_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_RDISC, NMRDiscClass))

#define NM_RDISC_PLATFORM       "platform"
#define NM_RDISC_IFINDEX        "ifindex"
#define NM_RDISC_IFNAME         "ifname"
#define NM_RDISC_NETWORK_ID     "network-id"
#define NM_RDISC_ADDR_GEN_MODE  "addr-gen-mode"
#define NM_RDISC_STABLE_TYPE    "stable-type"
#define NM_RDISC_MAX_ADDRESSES  "max-addresses"
#define NM_RDISC_ROUTER_SOLICITATIONS "router-solicitations"
#define NM_RDISC_ROUTER_SOLICITATION_INTERVAL "router-solicitation-interval"

#define NM_RDISC_CONFIG_CHANGED "config-changed"
#define NM_RDISC_RA_TIMEOUT     "ra-timeout"

typedef enum {
	NM_RDISC_DHCP_LEVEL_UNKNOWN,
	NM_RDISC_DHCP_LEVEL_NONE,
	NM_RDISC_DHCP_LEVEL_OTHERCONF,
	NM_RDISC_DHCP_LEVEL_MANAGED
} NMRDiscDHCPLevel;

typedef enum {
	NM_RDISC_PREFERENCE_INVALID,
	NM_RDISC_PREFERENCE_LOW,
	NM_RDISC_PREFERENCE_MEDIUM,
	NM_RDISC_PREFERENCE_HIGH
} NMRDiscPreference;

typedef struct {
	struct in6_addr address;
	guint32 timestamp;
	guint32 lifetime;
	NMRDiscPreference preference;
} NMRDiscGateway;

typedef struct {
	struct in6_addr address;
	guint8 dad_counter;
	guint32 timestamp;
	guint32 lifetime;
	guint32 preferred;
} NMRDiscAddress;

typedef struct {
	struct in6_addr network;
	guint8 plen;
	struct in6_addr gateway;
	guint32 timestamp;
	guint32 lifetime;
	NMRDiscPreference preference;
} NMRDiscRoute;

typedef struct {
	struct in6_addr address;
	guint32 timestamp;
	guint32 lifetime;
} NMRDiscDNSServer;

typedef struct {
	char *domain;
	guint32 timestamp;
	guint32 lifetime;
} NMRDiscDNSDomain;

typedef enum {
	NM_RDISC_CONFIG_DHCP_LEVEL                          = 1 << 0,
	NM_RDISC_CONFIG_GATEWAYS                            = 1 << 1,
	NM_RDISC_CONFIG_ADDRESSES                           = 1 << 2,
	NM_RDISC_CONFIG_ROUTES                              = 1 << 3,
	NM_RDISC_CONFIG_DNS_SERVERS                         = 1 << 4,
	NM_RDISC_CONFIG_DNS_DOMAINS                         = 1 << 5,
	NM_RDISC_CONFIG_HOP_LIMIT                           = 1 << 6,
	NM_RDISC_CONFIG_MTU                                 = 1 << 7,
} NMRDiscConfigMap;

#define NM_RDISC_MAX_ADDRESSES_DEFAULT 16
#define NM_RDISC_ROUTER_SOLICITATIONS_DEFAULT 3
#define NM_RDISC_ROUTER_SOLICITATION_INTERVAL_DEFAULT 4

struct _NMRDiscPrivate;
struct _NMRDiscDataInternal;

typedef struct {
	NMRDiscDHCPLevel dhcp_level;
	guint32 mtu;
	int hop_limit;

	guint gateways_n;
	guint addresses_n;
	guint routes_n;
	guint dns_servers_n;
	guint dns_domains_n;

	const NMRDiscGateway *gateways;
	const NMRDiscAddress *addresses;
	const NMRDiscRoute *routes;
	const NMRDiscDNSServer *dns_servers;
	const NMRDiscDNSDomain *dns_domains;
} NMRDiscData;

/**
 * NMRDisc:
 *
 * Interface-specific structure that handles incoming router advertisements,
 * caches advertised items and removes them when they are obsolete.
 */
typedef struct {
	GObject parent;
	union {
		struct _NMRDiscPrivate *_priv;
		struct _NMRDiscDataInternal *rdata;
	};
} NMRDisc;

typedef struct {
	GObjectClass parent;

	void (*start) (NMRDisc *rdisc);
	gboolean (*send_rs) (NMRDisc *rdisc, GError **error);
} NMRDiscClass;

GType nm_rdisc_get_type (void);

int nm_rdisc_get_ifindex (NMRDisc *self);
const char *nm_rdisc_get_ifname (NMRDisc *self);

gboolean nm_rdisc_set_iid (NMRDisc *rdisc, const NMUtilsIPv6IfaceId iid);
void nm_rdisc_start (NMRDisc *rdisc);
void nm_rdisc_dad_failed (NMRDisc *rdisc, struct in6_addr *address);

NMPlatform *nm_rdisc_get_platform (NMRDisc *self);
NMPNetns *nm_rdisc_netns_get (NMRDisc *self);
gboolean nm_rdisc_netns_push (NMRDisc *self, NMPNetns **netns);

#endif /* __NETWORKMANAGER_RDISC_H__ */