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
|
diff --git a/src/backends/NetworkManagerDebian.c b/src/backends/NetworkManagerDebian.c
index 740572a..3a2fdd6 100644
--- a/src/backends/NetworkManagerDebian.c
+++ b/src/backends/NetworkManagerDebian.c
@@ -37,6 +37,7 @@ #include "interface_parser.h"
#include "nm-utils.h"
#define ARPING "/usr/sbin/arping"
+#define RESOLVCONF "resolvconf"
/*
* nm_system_init
@@ -514,13 +515,60 @@ gboolean nm_system_device_get_use_dhcp (
/*
* nm_system_device_get_disabled
*
- * Return whether the distro-specific system config tells us to use
- * dhcp for this device.
+ * Return whether the distro-specific system config tells us to disable
+ * this device.
*
*/
gboolean nm_system_device_get_disabled (NMDevice *dev)
{
- return FALSE;
+ const char *iface;
+ if_block *curr_device, *curr_b;
+ if_data *curr_d;
+ gboolean blacklist = TRUE;
+
+ g_return_val_if_fail (dev != NULL, TRUE);
+
+ iface = nm_device_get_iface (dev);
+
+ ifparser_init ();
+
+ /* If the device is listed in a mapping, do not control it */
+ if (ifparser_getmapping (iface) != NULL) {
+ blacklist = TRUE;
+ goto out;
+ }
+
+ /* If the interface isn't listed in /etc/network/interfaces then
+ * it's considered okay to control it.
+ */
+ curr_device = ifparser_getif (iface);
+ if (curr_device == NULL) {
+ blacklist = FALSE;
+ goto out;
+ }
+
+ /* If the interface is listed and isn't marked "auto" then it's
+ * definitely not okay to control it.
+ */
+ for (curr_b = ifparser_getfirst (); curr_b; curr_b = curr_b->next) {
+ if ((!strcmp (curr_b->type, "auto") || !strcmp (curr_b->type, "allow-hotplug"))
+ && strstr (curr_b->name, iface))
+ blacklist = FALSE;
+ }
+
+ /* If the interface has no options other than just "inet dhcp"
+ * it's probably ok to fiddle with it.
+ */
+ for (curr_d = curr_device->info; curr_d; curr_d = curr_d->next) {
+ if (strcmp (curr_d->key, "inet")
+ || strcmp (curr_d->data, "dhcp" ))
+ blacklist = TRUE;
+ }
+
+out:
+ ifparser_destroy ();
+
+ return blacklist;
}
@@ -563,12 +611,18 @@ gboolean nm_system_deactivate_dialup (GS
if (strcmp (dialup, config->name) == 0)
{
char *cmd;
+ int status;
nm_info ("Deactivating dialup device %s (%s) ...", dialup, (char *) config->data);
cmd = g_strdup_printf ("/sbin/ifdown %s", (char *) config->data);
nm_spawn_process (cmd);
g_free (cmd);
- ret = TRUE;
+ if (status == 0) {
+ ret = TRUE;
+ } else {
+ nm_warning ("Couldn't deactivate dialup device %s (%s) - %d", dialup, (char *) config->data, status);
+ ret = FALSE;
+ }
break;
}
}
@@ -587,12 +641,18 @@ gboolean nm_system_activate_dialup (GSLi
if (strcmp (dialup, config->name) == 0)
{
char *cmd;
+ int status;
nm_info ("Activating dialup device %s (%s) ...", dialup, (char *) config->data);
cmd = g_strdup_printf ("/sbin/ifup %s", (char *) config->data);
nm_spawn_process (cmd);
g_free (cmd);
- ret = TRUE;
+ if (status == 0) {
+ ret = TRUE;
+ } else {
+ nm_warning ("Couldn't activate dialup device %s (%s) - %d", dialup, (char *) config->data, status);
+ ret = FALSE;
+ }
break;
}
}
@@ -603,23 +663,26 @@ gboolean nm_system_activate_dialup (GSLi
GSList * nm_system_get_dialup_config (void)
{
const char *buf;
- unsigned int i = 0;
+ const char *provider;
GSList *list = NULL;
if_block *curr;
ifparser_init();
/* FIXME: get all ppp(and others?) lines from /e/n/i here */
curr = ifparser_getfirst();
- while(curr!=NULL)
+ while (curr != NULL)
{
NMDialUpConfig *config;
- if (strcmp(curr->type,"iface")==0)
+ if (strcmp(curr->type, "iface") == 0)
{
- buf = ifparser_getkey(curr,"inet");
- if (buf && strcmp (buf, "ppp")==0)
+ buf = ifparser_getkey(curr, "inet");
+ if (buf && strcmp (buf, "ppp") == 0)
{
+ provider = ifparser_getkey(curr, "provider");
+ if (!provider)
+ provider = "default provider";
config = g_malloc (sizeof (NMDialUpConfig));
- config->name = g_strdup_printf ("Modem (#%d)", i++);
+ config->name = g_strdup_printf ("%s via Modem", provider);
config->data = g_strdup (curr->name); /* interface name */
list = g_slist_append (list, config);
@@ -631,14 +694,6 @@ GSList * nm_system_get_dialup_config (vo
}
ifparser_destroy();
- /* Hack: Go back and remove the "(#0)" if there is only one device */
- if (i == 1)
- {
- NMDialUpConfig *config = (NMDialUpConfig *) list->data;
- g_free (config->name);
- config->name = g_strdup ("Modem");
- }
-
return list;
}
@@ -679,7 +734,10 @@ void nm_system_set_hostname (NMIP4Config
*/
gboolean nm_system_should_modify_resolv_conf (void)
{
- return TRUE;
+ if (g_find_program_in_path(RESOLVCONF) != NULL)
+ return FALSE;
+ else
+ return TRUE;
}
diff --git a/src/backends/interface_parser.c b/src/backends/interface_parser.c
index 53d6487..aa81134 100644
--- a/src/backends/interface_parser.c
+++ b/src/backends/interface_parser.c
@@ -198,6 +198,18 @@ if_block *ifparser_getif(const char* ifa
return NULL;
}
+if_block *ifparser_getmapping(const char* iface)
+{
+ if_block *curr = first;
+ while(curr!=NULL)
+ {
+ if (strcmp(curr->type,"mapping")==0 && strcmp(curr->name,iface)==0)
+ return curr;
+ curr = curr->next;
+ }
+ return NULL;
+}
+
const char *ifparser_getkey(if_block* iface, const char *key)
{
if_data *curr = iface->info;
diff --git a/src/backends/interface_parser.h b/src/backends/interface_parser.h
index 075f454..8914283 100644
--- a/src/backends/interface_parser.h
+++ b/src/backends/interface_parser.h
@@ -44,6 +44,7 @@ void ifparser_init(void);
void ifparser_destroy(void);
if_block *ifparser_getif(const char* iface);
+if_block *ifparser_getmapping(const char* iface);
if_block *ifparser_getfirst(void);
const char *ifparser_getkey(if_block* iface, const char *key);
|