-
Notifications
You must be signed in to change notification settings - Fork 173
/
nm-device.c
19049 lines (16097 loc) · 695 KB
/
nm-device.c
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2005 - 2018 Red Hat, Inc.
* Copyright (C) 2006 - 2008 Novell, Inc.
*/
#include "src/core/nm-default-daemon.h"
#include "nm-device.h"
#include <unistd.h>
#include <sys/ioctl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <linux/if.h>
#include <linux/if_addr.h>
#include <linux/rtnetlink.h>
#include <linux/if_ether.h>
#include <linux/if_infiniband.h>
#include "libnm-std-aux/unaligned.h"
#include "libnm-glib-aux/nm-dedup-multi.h"
#include "libnm-glib-aux/nm-random-utils.h"
#include "libnm-systemd-shared/nm-sd-utils-shared.h"
#include "libnm-base/nm-ethtool-base.h"
#include "libnm-core-aux-intern/nm-common-macros.h"
#include "nm-device-private.h"
#include "nm-l3cfg.h"
#include "nm-l3-config-data.h"
#include "NetworkManagerUtils.h"
#include "nm-manager.h"
#include "libnm-platform/nm-platform.h"
#include "libnm-platform/nm-platform-utils.h"
#include "libnm-platform/nmp-object.h"
#include "libnm-platform/nmp-rules-manager.h"
#include "ndisc/nm-ndisc.h"
#include "ndisc/nm-lndp-ndisc.h"
#include "dhcp/nm-dhcp-manager.h"
#include "dhcp/nm-dhcp-utils.h"
#include "nm-act-request.h"
#include "nm-proxy-config.h"
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
#include "nm-pacrunner-manager.h"
#include "dnsmasq/nm-dnsmasq-manager.h"
#include "nm-dhcp-config.h"
#include "nm-rfkill-manager.h"
#include "nm-firewall-manager.h"
#include "settings/nm-settings-connection.h"
#include "settings/nm-settings.h"
#include "nm-setting-ethtool.h"
#include "nm-setting-ovs-external-ids.h"
#include "nm-setting-user.h"
#include "nm-auth-utils.h"
#include "nm-keep-alive.h"
#include "nm-netns.h"
#include "nm-dispatcher.h"
#include "nm-config.h"
#include "c-list/src/c-list.h"
#include "dns/nm-dns-manager.h"
#include "nm-acd-manager.h"
#include "libnm-core-intern/nm-core-internal.h"
#include "systemd/nm-sd.h"
#include "nm-lldp-listener.h"
#include "nm-audit-manager.h"
#include "nm-connectivity.h"
#include "nm-dbus-interface.h"
#include "nm-device-generic.h"
#include "nm-device-vlan.h"
#include "nm-device-vrf.h"
#include "nm-device-wireguard.h"
#include "nm-device-logging.h"
/*****************************************************************************/
#define DEFAULT_AUTOCONNECT TRUE
static guint32
dhcp_grace_period_from_timeout(guint32 timeout)
{
#define DHCP_GRACE_PERIOD_MULTIPLIER 2U
nm_assert(timeout > 0);
nm_assert(timeout < G_MAXINT32);
if (timeout < G_MAXUINT32 / DHCP_GRACE_PERIOD_MULTIPLIER)
return timeout * DHCP_GRACE_PERIOD_MULTIPLIER;
return G_MAXUINT32;
}
#define CARRIER_WAIT_TIME_MS 6000
#define CARRIER_WAIT_TIME_AFTER_MTU_MS 10000
#define NM_DEVICE_AUTH_RETRIES_UNSET -1
#define NM_DEVICE_AUTH_RETRIES_INFINITY -2
#define NM_DEVICE_AUTH_RETRIES_DEFAULT 3
/*****************************************************************************/
typedef void (*ActivationHandleFunc)(NMDevice *self);
typedef enum {
CLEANUP_TYPE_KEEP,
CLEANUP_TYPE_REMOVED,
CLEANUP_TYPE_DECONFIGURE,
} CleanupType;
typedef struct {
CList lst_slave;
NMDevice *slave;
gulong watch_id;
bool slave_is_enslaved;
bool configure;
} SlaveInfo;
typedef struct {
NMDevice *device;
guint idle_add_id;
int ifindex;
} DeleteOnDeactivateData;
typedef struct {
NMDevice * device;
GCancellable * cancellable;
NMPlatformAsyncCallback callback;
gpointer callback_data;
guint num_vfs;
NMOptionBool autoprobe;
} SriovOp;
typedef void (*AcdCallback)(NMDevice *, NMIP4Config **, gboolean);
typedef enum {
/* The various NML3ConfigData types that we track explicitly. Note that
* their relative order matters: higher numbers in this enum means more
* important (and during merge overwrites other settings). */
L3_CONFIG_DATA_TYPE_LL_4,
L3_CONFIG_DATA_TYPE_AC_6,
L3_CONFIG_DATA_TYPE_DHCP_4,
L3_CONFIG_DATA_TYPE_DHCP_6,
L3_CONFIG_DATA_TYPE_DEV_4,
L3_CONFIG_DATA_TYPE_DEV_6,
L3_CONFIG_DATA_TYPE_SETTING,
_L3_CONFIG_DATA_TYPE_NUM,
_L3_CONFIG_DATA_TYPE_NONE,
} L3ConfigDataType;
typedef struct {
AcdCallback callback;
NMDevice * device;
NMIP4Config **configs;
} AcdData;
typedef enum {
HW_ADDR_TYPE_UNSET = 0,
HW_ADDR_TYPE_PERMANENT,
HW_ADDR_TYPE_EXPLICIT,
HW_ADDR_TYPE_GENERATED,
} HwAddrType;
typedef enum {
FIREWALL_STATE_UNMANAGED = 0,
FIREWALL_STATE_INITIALIZED,
FIREWALL_STATE_WAIT_STAGE_3,
FIREWALL_STATE_WAIT_IP_CONFIG,
} FirewallState;
typedef struct {
NMIPConfig *orig; /* the original configuration applied to the device */
NMIPConfig *current; /* configuration after external changes. NULL means
* that the original configuration didn't change. */
} AppliedConfig;
typedef struct {
NMDhcpClient *client;
NMDhcpConfig *config;
gulong state_sigid;
guint grace_id;
bool grace_pending : 1;
bool was_active : 1;
} DhcpData;
struct _NMDeviceConnectivityHandle {
CList concheck_lst;
NMDevice * self;
NMDeviceConnectivityCallback callback;
gpointer user_data;
NMConnectivityCheckHandle * c_handle;
guint64 seq;
bool is_periodic : 1;
bool is_periodic_bump : 1;
bool is_periodic_bump_on_complete : 1;
int addr_family;
};
typedef struct {
int ifindex;
NMEthtoolFeatureStates *features;
NMOptionBool requested[_NM_ETHTOOL_ID_FEATURE_NUM];
NMEthtoolCoalesceState *coalesce;
NMEthtoolRingState * ring;
} EthtoolState;
typedef enum {
RESOLVER_WAIT_ADDRESS = 0,
RESOLVER_IN_PROGRESS,
RESOLVER_DONE,
} ResolverState;
typedef struct {
ResolverState state;
GResolver * resolver;
GInetAddress *address;
GCancellable *cancellable;
char * hostname;
NMDevice * device;
guint timeout_id; /* Used when waiting for the address */
int addr_family;
} HostnameResolver;
/*****************************************************************************/
enum {
STATE_CHANGED,
AUTOCONNECT_ALLOWED,
IP4_CONFIG_CHANGED,
IP6_CONFIG_CHANGED,
IP6_PREFIX_DELEGATED,
IP6_SUBNET_NEEDED,
REMOVED,
RECHECK_AUTO_ACTIVATE,
RECHECK_ASSUME,
DNS_LOOKUP_DONE,
LAST_SIGNAL,
};
static guint signals[LAST_SIGNAL] = {0};
NM_GOBJECT_PROPERTIES_DEFINE(NMDevice,
PROP_UDI,
PROP_PATH,
PROP_IFACE,
PROP_IP_IFACE,
PROP_DRIVER,
PROP_DRIVER_VERSION,
PROP_FIRMWARE_VERSION,
PROP_CAPABILITIES,
PROP_CARRIER,
PROP_MTU,
PROP_IP4_ADDRESS,
PROP_IP4_CONFIG,
PROP_DHCP4_CONFIG,
PROP_IP6_CONFIG,
PROP_DHCP6_CONFIG,
PROP_STATE,
PROP_STATE_REASON,
PROP_ACTIVE_CONNECTION,
PROP_DEVICE_TYPE,
PROP_LINK_TYPE,
PROP_MANAGED,
PROP_AUTOCONNECT,
PROP_FIRMWARE_MISSING,
PROP_NM_PLUGIN_MISSING,
PROP_TYPE_DESC,
PROP_RFKILL_TYPE,
PROP_IFINDEX,
PROP_AVAILABLE_CONNECTIONS,
PROP_PHYSICAL_PORT_ID,
PROP_MASTER,
PROP_PARENT,
PROP_HW_ADDRESS,
PROP_PERM_HW_ADDRESS,
PROP_HAS_PENDING_ACTION,
PROP_METERED,
PROP_LLDP_NEIGHBORS,
PROP_REAL,
PROP_SLAVES,
PROP_STATISTICS_REFRESH_RATE_MS,
PROP_STATISTICS_TX_BYTES,
PROP_STATISTICS_RX_BYTES,
PROP_IP4_CONNECTIVITY,
PROP_IP6_CONNECTIVITY,
PROP_INTERFACE_FLAGS, );
typedef struct _NMDevicePrivate {
bool in_state_changed;
guint device_link_changed_id;
guint device_ip_link_changed_id;
NMDeviceState state;
NMDeviceStateReason state_reason;
struct {
guint id;
/* The @state/@reason is only valid, when @id is set. */
NMDeviceState state;
NMDeviceStateReason reason;
} queued_state;
union {
struct {
guint queued_ip_config_id_6;
guint queued_ip_config_id_4;
};
guint queued_ip_config_id_x[2];
};
GSList *pending_actions;
GSList *dad6_failed_addrs;
NMDBusTrackObjPath parent_device;
char *udi;
char *path;
union {
const char *const iface;
char * iface_;
};
union {
const char *const ip_iface;
char * ip_iface_;
};
union {
const int ifindex;
int ifindex_;
};
union {
const int ip_ifindex;
int ip_ifindex_;
};
NMNetnsSharedIPHandle *shared_ip_handle;
int parent_ifindex;
int auth_retries;
union {
struct {
HostnameResolver *hostname_resolver_6;
HostnameResolver *hostname_resolver_4;
};
HostnameResolver *hostname_resolver_x[2];
};
union {
const guint8 hw_addr_len; /* read-only */
guint8 hw_addr_len_;
};
HwAddrType hw_addr_type : 5;
bool real : 1;
bool update_ip_config_completed_v4 : 1;
bool update_ip_config_completed_v6 : 1;
NMDeviceType type;
char * type_desc;
NMLinkType link_type;
NMDeviceCapabilities capabilities;
char * driver;
char * driver_version;
char * firmware_version;
RfKillType rfkill_type;
bool firmware_missing : 1;
bool nm_plugin_missing : 1;
bool
hw_addr_perm_fake : 1; /* whether the permanent HW address could not be read and is a fake */
NMUtilsStableType current_stable_id_type : 3;
bool nm_owned : 1; /* whether the device is a device owned and created by NM */
bool assume_state_guess_assume : 1;
char *assume_state_connection_uuid;
guint64 udi_id;
GHashTable *available_connections;
char * hw_addr;
char * hw_addr_perm;
char * hw_addr_initial;
char * physical_port_id;
guint dev_id;
NMUnmanagedFlags unmanaged_mask;
NMUnmanagedFlags unmanaged_flags;
DeleteOnDeactivateData
*delete_on_deactivate_data; /* data for scheduled cleanup when deleting link (g_idle_add) */
GCancellable *deactivating_cancellable;
NMActRequest * queued_act_request;
bool queued_act_request_is_waiting_for_carrier : 1;
NMDBusTrackObjPath act_request;
union {
struct {
guint activation_source_id_6;
guint activation_source_id_4; /* for layer2 and IPv4. */
};
guint activation_source_id_x[2];
};
union {
struct {
ActivationHandleFunc activation_source_func_6;
ActivationHandleFunc activation_source_func_4; /* for layer2 and IPv4. */
};
ActivationHandleFunc activation_source_func_x[2];
};
guint recheck_assume_id;
struct {
guint call_id;
NMDeviceStateReason available_reason;
NMDeviceStateReason unavailable_reason;
} recheck_available;
struct {
NMDispatcherCallId *call_id;
NMDeviceState post_state;
NMDeviceStateReason post_state_reason;
} dispatcher;
/* Link stuff */
guint link_connected_id;
guint link_disconnected_id;
guint carrier_defer_id;
guint carrier_wait_id;
gulong config_changed_id;
gulong ifindex_changed_id;
guint32 mtu;
guint32 ip6_mtu;
guint32 mtu_initial;
guint32 ip6_mtu_initial;
NMDeviceMtuSource mtu_source;
guint32 v4_route_table;
guint32 v6_route_table;
/* when carrier goes away, we give a grace period of _get_carrier_wait_ms()
* until taking action.
*
* When changing MTU, the device might take longer then that. So, whenever
* NM changes the MTU it sets @carrier_wait_until_ms to CARRIER_WAIT_TIME_AFTER_MTU_MS
* in the future. This is used to extend the grace period in this particular case. */
gint64 carrier_wait_until_ms;
union {
const NMDeviceSysIfaceState sys_iface_state;
NMDeviceSysIfaceState sys_iface_state_;
};
bool carrier : 1;
bool ignore_carrier : 1;
bool up : 1; /* IFF_UP */
bool v4_commit_first_time : 1;
bool v6_commit_first_time : 1;
bool default_route_metric_penalty_ip4_has : 1;
bool default_route_metric_penalty_ip6_has : 1;
bool v4_route_table_initialized : 1;
bool v6_route_table_initialized : 1;
bool l3config_merge_flags_has : 1;
bool v4_route_table_all_sync_before : 1;
bool v6_route_table_all_sync_before : 1;
NMDeviceAutoconnectBlockedFlags autoconnect_blocked_flags : 5;
bool is_enslaved : 1;
bool ipv6ll_handle : 1; /* TRUE if NM handles the device's IPv6LL address */
bool ipv6ll_has : 1;
bool ndisc_started : 1;
bool device_link_changed_down : 1;
bool concheck_rp_filter_checked : 1;
NMDeviceStageState stage1_sriov_state : 3;
/* Generic DHCP stuff */
char *dhcp_anycast_address;
char *current_stable_id;
/* Proxy Configuration */
NMProxyConfig * proxy_config;
NMPacrunnerConfId *pacrunner_conf_id;
/* IP configuration info. Combined config from VPN, settings, and device */
union {
struct {
NMIP6Config *ip_config_6;
NMIP4Config *ip_config_4;
};
NMIPConfig *ip_config_x[2];
};
/* Config from DHCP, PPP, LLv4, etc */
AppliedConfig dev_ip_config_4;
/* config from the setting */
union {
struct {
NMIP6Config *con_ip_config_6;
NMIP4Config *con_ip_config_4;
};
NMIPConfig *con_ip_config_x[2];
};
/* Stuff added outside NM */
union {
struct {
NMIP6Config *ext_ip_config_6;
NMIP4Config *ext_ip_config_4;
};
NMIPConfig *ext_ip_config_x[2];
};
/* VPNs which use this device */
union {
struct {
GSList *vpn_configs_6;
GSList *vpn_configs_4;
};
GSList *vpn_configs_x[2];
};
/* Extra device configuration, injected by the subclass of NMDevice.
* This is used for example by NMDeviceModem for WWAN configuration. */
union {
struct {
AppliedConfig dev2_ip_config_6;
AppliedConfig dev2_ip_config_4;
};
AppliedConfig dev2_ip_config_x[2];
};
/* DHCPv4 tracking */
struct {
char *pac_url;
} dhcp4;
struct {
/* IP6 config from DHCP */
AppliedConfig ip6_config;
/* Event ID of the current IP6 config from DHCP */
char * event_id;
gulong prefix_sigid;
NMNDiscDHCPLevel mode;
guint needed_prefixes;
} dhcp6;
union {
struct {
DhcpData dhcp_data_6;
DhcpData dhcp_data_4;
};
DhcpData dhcp_data_x[2];
};
struct {
NMLogDomain log_domain;
guint timeout;
guint watch;
GPid pid;
char * binary;
char * address;
guint deadline;
} gw_ping;
/* dnsmasq stuff for shared connections */
NMDnsMasqManager *dnsmasq_manager;
gulong dnsmasq_state_id;
/* Firewall */
FirewallState fw_state : 4;
NMFirewallManager * fw_mgr;
NMFirewallManagerCallId *fw_call;
/* IPv4LL stuff */
sd_ipv4ll *ipv4ll;
guint ipv4ll_timeout;
guint rt6_temporary_not_available_id;
/* IPv4 DAD stuff */
struct {
GSList * dad_list;
NMAcdManager *announcing;
} acd;
union {
struct {
const NMDeviceIPState ip_state_6;
const NMDeviceIPState ip_state_4;
};
union {
const NMDeviceIPState ip_state_x[2];
NMDeviceIPState ip_state_x_[2];
};
};
AppliedConfig ac_ip6_config; /* config from IPv6 autoconfiguration */
NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */
NMIP6Config * dad6_ip6_config;
struct in6_addr ipv6ll_addr;
GHashTable *rt6_temporary_not_available;
NMNDisc * ndisc;
gulong ndisc_changed_id;
gulong ndisc_timeout_id;
NMSettingIP6ConfigPrivacy ndisc_use_tempaddr;
guint linklocal6_timeout_id;
guint8 linklocal6_dad_counter;
GHashTable *ip6_saved_properties;
EthtoolState *ethtool_state;
gboolean needs_ip6_subnet;
/* master interface for bridge/bond/team slave */
NMDevice *master;
gulong master_ready_id;
int master_ifindex;
/* slave management */
CList slaves; /* list of SlaveInfo */
NMMetered metered;
NMSettings *settings;
NMManager * manager;
NMNetns *netns;
NMLldpListener *lldp_listener;
NMConnectivity *concheck_mgr;
CList concheck_lst_head;
struct {
/* if periodic checks are enabled, this is the source id for the next check. */
guint p_cur_id;
/* the currently configured max periodic interval. */
guint p_max_interval;
/* the current interval. If we are probing, the interval might be lower
* then the configured max interval. */
guint p_cur_interval;
/* the timestamp, when we last scheduled the timer p_cur_id with current interval
* p_cur_interval. */
gint64 p_cur_basetime_ns;
NMConnectivityState state;
} concheck_x[2];
guint check_delete_unrealized_id;
guint32 interface_flags;
struct {
SriovOp *pending; /* SR-IOV operation currently running */
SriovOp *next; /* next SR-IOV operation scheduled */
} sriov;
guint sriov_reset_pending;
struct {
guint timeout_id;
guint refresh_rate_ms;
guint64 tx_bytes;
guint64 rx_bytes;
} stats;
bool mtu_force_set_done : 1;
} NMDevicePrivate;
G_DEFINE_ABSTRACT_TYPE(NMDevice, nm_device, NM_TYPE_DBUS_OBJECT)
#define NM_DEVICE_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMDevice, NM_IS_DEVICE)
/*****************************************************************************/
static const NMDBusInterfaceInfoExtended interface_info_device;
static const GDBusSignalInfo signal_info_state_changed;
static void nm_device_set_proxy_config(NMDevice *self, const char *pac_url);
static gboolean update_ext_ip_config(NMDevice *self, int addr_family, gboolean intersect_configs);
static gboolean nm_device_set_ip_config(NMDevice * self,
int addr_family,
NMIPConfig *config,
gboolean commit,
GPtrArray * ip4_dev_route_blacklist);
static gboolean ip_config_merge_and_apply(NMDevice *self, int addr_family, gboolean commit);
static gboolean nm_device_master_add_slave(NMDevice *self, NMDevice *slave, gboolean configure);
static void nm_device_slave_notify_enslave(NMDevice *self, gboolean success);
static void nm_device_slave_notify_release(NMDevice *self, NMDeviceStateReason reason);
static void addrconf6_start_with_link_ready(NMDevice *self);
static gboolean linklocal6_start(NMDevice *self);
static guint32 default_route_metric_penalty_get(NMDevice *self, int addr_family);
static guint _prop_get_ipv4_dad_timeout(NMDevice *self);
static NMIP6Config *dad6_get_pending_addresses(NMDevice *self);
static void _carrier_wait_check_queued_act_request(NMDevice *self);
static gint64 _get_carrier_wait_ms(NMDevice *self);
static const char *_activation_func_to_string(ActivationHandleFunc func);
static void
_set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, gboolean quitting);
static void queued_state_clear(NMDevice *device);
static gboolean queued_ip4_config_change(gpointer user_data);
static gboolean queued_ip6_config_change(gpointer user_data);
static void ip_check_ping_watch_cb(GPid pid, int status, gpointer user_data);
static gboolean ip_config_valid(NMDeviceState state);
static NMActStageReturn dhcp4_start(NMDevice *self);
static gboolean dhcp6_start(NMDevice *self, gboolean wait_for_ll);
static void nm_device_start_ip_check(NMDevice *self);
static void realize_start_setup(NMDevice * self,
const NMPlatformLink *plink,
gboolean assume_state_guess_assume,
const char * assume_state_connection_uuid,
gboolean set_nm_owned,
NMUnmanFlagOp unmanaged_user_explicit,
gboolean force_platform_init);
static void _set_mtu(NMDevice *self, guint32 mtu);
static void _commit_mtu(NMDevice *self, const NMIP4Config *config);
static void _cancel_activation(NMDevice *self);
static void concheck_update_state(NMDevice * self,
int addr_family,
NMConnectivityState state,
gboolean is_periodic);
static void sriov_op_cb(GError *error, gpointer user_data);
static void device_ifindex_changed_cb(NMManager *manager, NMDevice *device_changed, NMDevice *self);
static gboolean device_link_changed(NMDevice *self);
/*****************************************************************************/
static NM_UTILS_LOOKUP_STR_DEFINE(
queued_state_to_string,
NMDeviceState,
NM_UTILS_LOOKUP_DEFAULT(NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "???"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_UNKNOWN,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "unknown"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_UNMANAGED,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "unmanaged"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_UNAVAILABLE,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "unavailable"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_DISCONNECTED,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "disconnected"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_PREPARE,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "prepare"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_CONFIG,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "config"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_NEED_AUTH,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "need-auth"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_IP_CONFIG,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "ip-config"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_IP_CHECK,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "ip-check"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_SECONDARIES,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "secondaries"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_ACTIVATED,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "activated"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_DEACTIVATING,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "deactivating"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_FAILED,
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "failed"), );
const char *
nm_device_state_to_str(NMDeviceState state)
{
return queued_state_to_string(state) + NM_STRLEN(NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE);
}
NM_UTILS_LOOKUP_STR_DEFINE(
nm_device_state_reason_to_str,
NMDeviceStateReason,
NM_UTILS_LOOKUP_DEFAULT(NULL),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNKNOWN, "unknown"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_NONE, "none"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_NOW_MANAGED, "managed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_NOW_UNMANAGED, "unmanaged"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_CONFIG_FAILED, "config-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE, "ip-config-unavailable"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED, "ip-config-expired"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_NO_SECRETS, "no-secrets"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT, "supplicant-disconnect"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED,
"supplicant-config-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED, "supplicant-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT, "supplicant-timeout"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_PPP_START_FAILED, "ppp-start-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_PPP_DISCONNECT, "ppp-disconnect"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_PPP_FAILED, "ppp-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_DHCP_START_FAILED, "dhcp-start-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_DHCP_ERROR, "dhcp-error"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_DHCP_FAILED, "dhcp-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SHARED_START_FAILED, "sharing-start-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SHARED_FAILED, "sharing-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED, "autoip-start-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_AUTOIP_ERROR, "autoip-error"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_AUTOIP_FAILED, "autoip-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_BUSY, "modem-busy"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE, "modem-no-dialtone"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER, "modem-no-carrier"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT, "modem-dial-timeout"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED, "modem-dial-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED, "modem-init-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_APN_FAILED, "gsm-apn-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING,
"gsm-registration-idle"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED,
"gsm-registration-denied"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT,
"gsm-registration-timeout"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED,
"gsm-registration-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED, "gsm-pin-check-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_FIRMWARE_MISSING, "firmware-missing"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_REMOVED, "removed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SLEEPING, "sleeping"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, "connection-removed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_USER_REQUESTED, "user-requested"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_CARRIER, "carrier-changed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED, "connection-assumed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE, "supplicant-available"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND, "modem-not-found"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_BT_FAILED, "bluetooth-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED, "gsm-sim-not-inserted"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED, "gsm-sim-pin-required"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED, "gsm-sim-puk-required"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_GSM_SIM_WRONG, "gsm-sim-wrong"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_INFINIBAND_MODE, "infiniband-mode"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED, "dependency-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_BR2684_FAILED, "br2684-bridge-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE,
"modem-manager-unavailable"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SSID_NOT_FOUND, "ssid-not-found"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED,
"secondary-connection-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED, "dcb-fcoe-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_TEAMD_CONTROL_FAILED, "teamd-control-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_FAILED, "modem-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_MODEM_AVAILABLE, "modem-available"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT, "sim-pin-incorrect"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_NEW_ACTIVATION, "new-activation"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_PARENT_CHANGED, "parent-changed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED,
"parent-managed-changed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_OVSDB_FAILED, "ovsdb-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE, "ip-address-duplicate"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_IP_METHOD_UNSUPPORTED, "ip-method-unsupported"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SRIOV_CONFIGURATION_FAILED,
"sriov-configuration-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_PEER_NOT_FOUND, "peer-not-found"), );
#define reason_to_string_a(reason) NM_UTILS_LOOKUP_STR_A(nm_device_state_reason_to_str, reason)
static NM_UTILS_LOOKUP_STR_DEFINE(mtu_source_to_str,
NMDeviceMtuSource,
NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT("unknown"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_MTU_SOURCE_NONE, "none"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_MTU_SOURCE_PARENT, "parent"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_MTU_SOURCE_IP_CONFIG,
"ip-config"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_MTU_SOURCE_CONNECTION,
"connection"), );
/*****************************************************************************/
static void
_hostname_resolver_free(HostnameResolver *resolver)
{
if (!resolver)
return;
nm_clear_g_source(&resolver->timeout_id);
nm_clear_g_cancellable(&resolver->cancellable);
nm_g_object_unref(resolver->resolver);
nm_g_object_unref(resolver->address);
g_free(resolver->hostname);
nm_g_slice_free(resolver);
}
/*****************************************************************************/
static NMSettingIP6ConfigPrivacy
_ip6_privacy_clamp(NMSettingIP6ConfigPrivacy use_tempaddr)
{
switch (use_tempaddr) {
case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED:
case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR:
case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR:
return use_tempaddr;
default:
return NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN;
}
}
/*****************************************************************************/
static const char *
_prop_get_connection_stable_id(NMDevice * self,
NMConnection * connection,
NMUtilsStableType *out_stable_type)
{
NMDevicePrivate *priv;
nm_assert(NM_IS_DEVICE(self));
nm_assert(NM_IS_CONNECTION(connection));
nm_assert(out_stable_type);
priv = NM_DEVICE_GET_PRIVATE(self);
/* we cache the generated stable ID for the time of an activation.
*
* The reason is, that we don't want the stable-id to change as long
* as the device is active.
*
* Especially with ${RANDOM} stable-id we want to generate *one* configuration
* for each activation. */
if (G_UNLIKELY(!priv->current_stable_id)) {
gs_free char * default_id = NULL;
gs_free char * generated = NULL;
NMUtilsStableType stable_type;
NMSettingConnection *s_con;
gboolean hwaddr_is_fake;
const char * hwaddr;
const char * stable_id;
const char * uuid;
s_con = nm_connection_get_setting_connection(connection);
stable_id = nm_setting_connection_get_stable_id(s_con);
if (!stable_id) {
default_id =
nm_config_data_get_connection_default(NM_CONFIG_GET_DATA,
NM_CON_DEFAULT("connection.stable-id"),
self);
stable_id = default_id;
}
uuid = nm_connection_get_uuid(connection);
/* the cloned-mac-address may be generated based on the stable-id.
* Thus, at this point, we can only use the permanent MAC address
* as seed. */
hwaddr = nm_device_get_permanent_hw_address_full(self, TRUE, &hwaddr_is_fake);
stable_type = nm_utils_stable_id_parse(stable_id,
nm_device_get_ip_iface(self),
!hwaddr_is_fake ? hwaddr : NULL,
nm_utils_boot_id_str(),
uuid,
&generated);
/* current_stable_id_type is a bitfield! */
priv->current_stable_id_type = stable_type;
nm_assert(stable_type <= (NMUtilsStableType) 0x3);
nm_assert(stable_type + (NMUtilsStableType) 1 > (NMUtilsStableType) 0);
nm_assert(priv->current_stable_id_type == stable_type);
if (stable_type == NM_UTILS_STABLE_TYPE_UUID)
priv->current_stable_id = g_strdup(uuid);
else if (stable_type == NM_UTILS_STABLE_TYPE_STABLE_ID)
priv->current_stable_id = g_strdup(stable_id);