1 /* SmoothWall libsmooth.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Contains network library functions.
11 #include <libsmooth.h>
16 #define _(x) dgettext("setup", x)
23 extern struct nic nics
[];
24 extern struct knic knics
[];
26 char *ucolourcard
[] = { "GREEN", "RED", "ORANGE", "BLUE", NULL
};
27 char *lcolourcard
[] = { "green", "red", "orange", "blue", NULL
};
29 int scanned_nics_read_done
= 0;
31 newtComponent networkform
;
32 newtComponent addressentry
;
33 newtComponent netmaskentry
;
34 newtComponent statictyperadio
;
35 newtComponent dhcptyperadio
;
36 newtComponent pppoetyperadio
;
37 newtComponent dhcphostnameentry
;
38 newtComponent dhcpforcemtuentry
;
40 /* acceptable character filter for IP and netmaks entry boxes */
41 static int ip_input_filter(newtComponent entry
, void * data
, int ch
, int cursor
)
43 if ((ch
>= '0' && ch
<= '9') || ch
== '.' || ch
== '\r' || ch
>= NEWT_KEY_EXTRA_BASE
)
48 /* This is a groovie dialog for showing network info. Takes a keyvalue list,
49 * a colour and a dhcp flag. Shows the current settings, and rewrites them
50 * if necessary. DHCP flag sets wether to show the dhcp checkbox. */
51 int changeaddress(struct keyvalue
*kv
, char *colour
, int typeflag
,
52 char *defaultdhcphostname
)
56 char *dhcphostnameresult
;
57 char *dhcpforcemturesult
;
58 struct newtExitStruct es
;
60 newtComponent addresslabel
;
61 newtComponent netmasklabel
;
62 newtComponent dhcphostnamelabel
;
63 newtComponent dhcpforcemtulabel
;
64 newtComponent ok
, cancel
;
66 char temp
[STRING_SIZE
];
67 char addressfield
[STRING_SIZE
];
68 char netmaskfield
[STRING_SIZE
];
69 char typefield
[STRING_SIZE
];
70 char dhcphostnamefield
[STRING_SIZE
];
71 char dhcpforcemtufield
[STRING_SIZE
];
74 char type
[STRING_SIZE
];
75 int startstatictype
= 0;
76 int startdhcptype
= 0;
77 int startpppoetype
= 0;
78 unsigned char buffer
[sizeof(struct in_addr
)];
80 /* Build some key strings. */
81 sprintf(addressfield
, "%s_ADDRESS", colour
);
82 sprintf(netmaskfield
, "%s_NETMASK", colour
);
83 sprintf(typefield
, "%s_TYPE", colour
);
84 sprintf(dhcphostnamefield
, "%s_DHCP_HOSTNAME", colour
);
85 sprintf(dhcpforcemtufield
, "%s_DHCP_FORCE_MTU", colour
);
87 sprintf(message
, _("Interface - %s"), colour
);
88 newtCenteredWindow(44, (typeflag
? 18 : 12), message
);
90 networkform
= newtForm(NULL
, NULL
, 0);
92 sprintf(message
, _("Enter the IP address information for the %s interface."), colour
);
93 header
= newtTextboxReflowed(1, 1, message
, 42, 0, 0, 0);
94 newtFormAddComponent(networkform
, header
);
96 /* See if we need a dhcp checkbox. If we do, then we shift the contents
97 * of the window down two rows to make room. */
100 strcpy(temp
, "STATIC"); findkey(kv
, typefield
, temp
);
101 if (strcmp(temp
, "STATIC") == 0) startstatictype
= 1;
102 if (strcmp(temp
, "DHCP") == 0) startdhcptype
= 1;
103 if (strcmp(temp
, "PPPOE") == 0) startpppoetype
= 1;
104 statictyperadio
= newtRadiobutton(2, 4, _("Static"), startstatictype
, NULL
);
105 dhcptyperadio
= newtRadiobutton(2, 5, _("DHCP"), startdhcptype
, statictyperadio
);
106 pppoetyperadio
= newtRadiobutton(2, 6, _("PPP DIALUP (PPPoE, modem, ATM ...)"),
107 startpppoetype
, dhcptyperadio
);
108 newtFormAddComponents(networkform
, statictyperadio
, dhcptyperadio
,
109 pppoetyperadio
, NULL
);
110 newtComponentAddCallback(statictyperadio
, networkdialogcallbacktype
, NULL
);
111 newtComponentAddCallback(dhcptyperadio
, networkdialogcallbacktype
, NULL
);
112 newtComponentAddCallback(pppoetyperadio
, networkdialogcallbacktype
, NULL
);
113 dhcphostnamelabel
= newtTextbox(2, 8, 18, 1, 0);
114 newtTextboxSetText(dhcphostnamelabel
, _("DHCP Hostname:"));
115 dhcpforcemtulabel
= newtTextbox(2, 9, 18, 1, 0);
116 newtTextboxSetText(dhcpforcemtulabel
, _("Force DHCP MTU:"));
117 strcpy(temp
, defaultdhcphostname
);
118 findkey(kv
, dhcphostnamefield
, temp
);
119 dhcphostnameentry
= newtEntry(20, 8, temp
, 20, &dhcphostnameresult
, 0);
121 findkey(kv
, dhcpforcemtufield
, temp
);
122 dhcpforcemtuentry
= newtEntry(20, 9, temp
, 20, &dhcpforcemturesult
, 0);
123 newtFormAddComponent(networkform
, dhcphostnamelabel
);
124 newtFormAddComponent(networkform
, dhcphostnameentry
);
125 newtFormAddComponent(networkform
, dhcpforcemtulabel
);
126 newtFormAddComponent(networkform
, dhcpforcemtuentry
);
127 if (startdhcptype
== 0)
129 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
130 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
134 addresslabel
= newtTextbox(2, (typeflag
? 11 : 4) + 0, 18, 1, 0);
135 newtTextboxSetText(addresslabel
, _("IP address:"));
137 findkey(kv
, addressfield
, temp
);
138 addressentry
= newtEntry(20, (typeflag
? 11 : 4) + 0, temp
, 20, &addressresult
, 0);
139 newtEntrySetFilter(addressentry
, ip_input_filter
, NULL
);
140 if (typeflag
== 1 && startstatictype
== 0)
141 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
142 newtFormAddComponent(networkform
, addresslabel
);
143 newtFormAddComponent(networkform
, addressentry
);
146 netmasklabel
= newtTextbox(2, (typeflag
? 11 : 4) + 1, 18, 1, 0);
147 newtTextboxSetText(netmasklabel
, _("Network mask:"));
148 strcpy(temp
, "255.255.255.0"); findkey(kv
, netmaskfield
, temp
);
149 netmaskentry
= newtEntry(20, (typeflag
? 11 : 4) + 1, temp
, 20, &netmaskresult
, 0);
150 newtEntrySetFilter(netmaskentry
, ip_input_filter
, NULL
);
151 if (typeflag
== 1 && startstatictype
== 0)
152 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
154 newtFormAddComponent(networkform
, netmasklabel
);
155 newtFormAddComponent(networkform
, netmaskentry
);
158 ok
= newtButton(8, (typeflag
? 14 : 7), _("OK"));
159 cancel
= newtButton(26, (typeflag
? 14 : 7), _("Cancel"));
161 newtFormAddComponents(networkform
, ok
, cancel
, NULL
);
164 newtDrawForm(networkform
);
169 newtFormRun(networkform
, &es
);
173 /* OK was pressed; verify the contents of each entry. */
174 strcpy(message
, _("The following fields are invalid:"));
175 strcat(message
, "\n\n");
177 strcpy(type
, "STATIC");
180 if (strcmp(type
, "STATIC") == 0)
182 if (inet_addr(addressresult
) == INADDR_NONE
)
184 strcat(message
, _("IP address"));
185 strcat(message
, "\n");
188 if (inet_pton(AF_INET
, netmaskresult
, &buffer
) == 0)
190 strcat(message
, _("Network mask"));
191 strcat(message
, "\n");
195 if (strcmp(type
, "DHCP") == 0)
197 if (!strlen(dhcphostnameresult
))
199 strcat(message
, _("DHCP hostname"));
200 strcat(message
, "\n");
208 /* No errors! Set new values, depending on dhcp flag etc. */
211 replacekeyvalue(kv
, dhcphostnamefield
, dhcphostnameresult
);
212 replacekeyvalue(kv
, dhcpforcemtufield
, dhcpforcemturesult
);
213 if (strcmp(type
, "STATIC") != 0)
215 replacekeyvalue(kv
, addressfield
, "0.0.0.0");
216 replacekeyvalue(kv
, netmaskfield
, "0.0.0.0");
220 replacekeyvalue(kv
, addressfield
, addressresult
);
221 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
223 replacekeyvalue(kv
, typefield
, type
);
227 replacekeyvalue(kv
, addressfield
, addressresult
);
228 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
231 setnetaddress(kv
, colour
);
235 /* Workaround for a bug that dhcp radiobutton also end the dialog at arm
238 if (es
.u
.co
!= cancel
) {
245 newtFormDestroy(networkform
);
251 /* for pppoe: return string thats type STATIC, DHCP or PPPOE */
252 int gettype(char *type
)
254 newtComponent selected
= newtRadioGetCurrent(statictyperadio
);
256 if (selected
== statictyperadio
)
257 strcpy(type
, "STATIC");
258 else if (selected
== dhcptyperadio
)
259 strcpy(type
, "DHCP");
260 else if (selected
== pppoetyperadio
)
261 strcpy(type
, "PPPOE");
263 strcpy(type
, "ERROR");
268 /* 0.9.9: calculates broadcast too. */
269 int setnetaddress(struct keyvalue
*kv
, char *colour
)
271 char addressfield
[STRING_SIZE
];
272 char netaddressfield
[STRING_SIZE
];
273 char netmaskfield
[STRING_SIZE
];
274 char broadcastfield
[STRING_SIZE
];
275 char address
[STRING_SIZE
];
276 char netmask
[STRING_SIZE
];
277 unsigned long int intaddress
;
278 unsigned long int intnetaddress
;
279 unsigned long int intnetmask
;
280 unsigned long int intbroadcast
;
285 /* Build some key strings. */
286 sprintf(addressfield
, "%s_ADDRESS", colour
);
287 sprintf(netaddressfield
, "%s_NETADDRESS", colour
);
288 sprintf(netmaskfield
, "%s_NETMASK", colour
);
289 sprintf(broadcastfield
, "%s_BROADCAST", colour
);
291 strcpy(address
, ""); findkey(kv
, addressfield
, address
);
292 strcpy(netmask
, ""); findkey(kv
, netmaskfield
, netmask
);
294 /* Calculate netaddress. Messy.. */
295 intaddress
= inet_addr(address
);
296 intnetmask
= inet_addr(netmask
);
298 intnetaddress
= intaddress
& intnetmask
;
299 temp
.s_addr
= intnetaddress
;
300 netaddress
= inet_ntoa(temp
);
302 replacekeyvalue(kv
, netaddressfield
, netaddress
);
304 intbroadcast
= intnetaddress
| ~intnetmask
;
305 temp
.s_addr
= intbroadcast
;
306 broadcast
= inet_ntoa(temp
);
308 replacekeyvalue(kv
, broadcastfield
, broadcast
);
313 /* Called when dhcp flag is toggled. Toggle disabled state of other 3
315 void networkdialogcallbacktype(newtComponent cm
, void *data
)
317 char type
[STRING_SIZE
];
321 if (strcmp(type
, "STATIC") != 0)
323 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
324 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
328 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
329 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
331 if (strcmp(type
, "DHCP") == 0)
333 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
334 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
338 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
339 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
342 newtDrawForm(networkform
);
345 int interfacecheck(struct keyvalue
*kv
, char *colour
)
347 char temp
[STRING_SIZE
];
348 char colourfields
[NETCHANGE_TOTAL
][STRING_SIZE
];
351 sprintf(colourfields
[ADDRESS
], "%s_ADDRESS", colour
);
352 sprintf(colourfields
[NETADDRESS
], "%s_NETADDRESS", colour
);
353 sprintf(colourfields
[NETMASK
], "%s_NETMASK", colour
);
355 for (c
= 0; c
< 3; c
++)
357 strcpy(temp
, ""); findkey(kv
, colourfields
[c
], temp
);
358 if (!(strlen(temp
))) return 0;
363 /* Funky routine for loading all drivers (cept those are already loaded.). */
364 int probecards(char *driver
, char *driveroptions
)
369 int get_knic(int card
) //returns "0" for zero cards or error and "1" card is found.
371 struct keyvalue
*kv
= initkeyvalues();
372 char temp
[STRING_SIZE
], searchstr
[STRING_SIZE
];
375 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
378 errorbox(_("Unable to open settings file"));
382 sprintf(searchstr
, "%s_MACADDR", ucolourcard
[card
]);
383 strcpy(temp
, ""); findkey(kv
, searchstr
, temp
);
385 strcpy(knics
[ card
].macaddr
, temp
);
386 strcpy(knics
[ card
].colour
, ucolourcard
[card
]);
388 sprintf(searchstr
, "%s_DESCRIPTION", ucolourcard
[card
]);
389 findkey(kv
, searchstr
, temp
);
390 strcpy(knics
[ card
].description
, temp
);
392 sprintf(searchstr
, "%s_DRIVER", ucolourcard
[card
]);
393 findkey(kv
, searchstr
, temp
);
394 strcpy(knics
[ card
].driver
, temp
);
397 strcpy(knics
[ card
].description
, _("Unset"));
408 found
+= get_knic(_GREEN_CARD_
);
409 found
+= get_knic(_RED_CARD_
);
410 found
+= get_knic(_ORANGE_CARD_
);
411 found
+= get_knic(_BLUE_CARD_
);
416 int fmt_exists(const char *fname
) { /* Check if it is any file or directory */
418 if (stat(fname
, &st
) == -1) return 0;
422 int is_interface_up(char *card
) { /* Check if the interface is UP */
423 char temp
[STRING_SIZE
];
425 sprintf(temp
,"ip link show dev %s | grep -q UP", card
);
426 if (mysystem(NULL
, temp
)) return 0; else return 1;
429 int rename_device(char *old_name
, char *new_name
) {
430 char temp
[STRING_SIZE
];
432 sprintf(temp
,SYSDIR
"/%s", old_name
);
433 if (!(fmt_exists(temp
))) {
434 fprintf(flog
,"Device not found: %s\n",old_name
);
437 sprintf(temp
,"/sbin/ip link set dev %s name %s",old_name
,new_name
);
438 mysystem(NULL
, temp
);
443 char g_temp
[STRING_SIZE
]="";
444 char* readmac(char *card
) {
446 char temp
[STRING_SIZE
], mac
[20];
448 sprintf(temp
,"/sys/class/net/%s/address",card
);
449 if( (fp
= fopen(temp
, "r")) == NULL
) {
450 fprintf(flog
,"Couldn't open: %s\n",temp
);
460 char* find_nic4mac(char *findmac
) {
462 struct dirent
*dirzeiger
;
463 char temp
[STRING_SIZE
], temp2
[STRING_SIZE
];
465 if((dir
=opendir(SYSDIR
)) == NULL
) {
466 fprintf(flog
,"Fehler bei opendir (find_name4nic) ...\n");
471 while((dirzeiger
=readdir(dir
)) != NULL
) {
472 if(*((*dirzeiger
).d_name
) != '.' & strcmp(((*dirzeiger
).d_name
), "lo") != 0) {
473 sprintf(temp2
, "%s", readmac((*dirzeiger
).d_name
) );
474 if (strcmp(findmac
, temp2
) == 0) {
475 sprintf(temp
,"%s", (*dirzeiger
).d_name
);
481 if(closedir(dir
) == -1) fprintf(flog
,"Fehler beim schliessen von %s\n", SYSDIR
);
482 strcpy(g_temp
, temp
);
486 int nic_shutdown(char *nic
) {
487 char temp
[STRING_SIZE
];
489 sprintf(temp
,"ip link set %s down", nic
);
490 mysystem(NULL
, temp
);
493 int nic_startup(char *nic
) {
494 char temp
[STRING_SIZE
];
496 sprintf(temp
,"ip link set %s up", nic
);
497 mysystem(NULL
, temp
);
501 int rename_nics(void) {
503 int fnics
= scan_network_cards();
504 char nic2find
[STRING_SIZE
], temp
[STRING_SIZE
];
507 if (strcmp(knics
[i
].macaddr
, ""))
508 for(j
=0; j
<fnics
; j
++)
509 if(strcmp(knics
[i
].macaddr
, nics
[j
].macaddr
) == 0) {
510 sprintf(nic2find
,"%s0",lcolourcard
[i
]);
511 if(strcmp(nic2find
, nics
[j
].nic
)) {
512 if(is_interface_up(nics
[j
].nic
)) {
513 nic_shutdown(nics
[j
].nic
);
515 sprintf(temp
,SYSDIR
"/%s", nic2find
);
516 if(fmt_exists(temp
)) {
517 for(k
=0; k
<fnics
; k
++)
518 if (strcmp(nics
[k
].nic
, nic2find
) == 0 ) {
519 if(is_interface_up(nics
[k
].nic
)) {
520 nic_shutdown(nics
[k
].nic
);
522 sprintf(temp
,"dummy%i",k
);
523 if (rename_device(nics
[k
].nic
, temp
)) strcpy(nics
[k
].nic
, temp
);
526 if (rename_device(nics
[j
].nic
, nic2find
)) strcpy(nics
[j
].nic
, nic2find
);
531 int write_configs_netudev(int card
, int colour
)
533 char commandstring
[STRING_SIZE
];
534 struct keyvalue
*kv
= initkeyvalues();
535 char temp1
[STRING_SIZE
], temp2
[STRING_SIZE
], temp3
[STRING_SIZE
];
536 char ucolour
[STRING_SIZE
];
538 sprintf(ucolour
, ucolourcard
[colour
]);
539 strcpy(knics
[colour
].driver
, nics
[card
].driver
);
540 strcpy(knics
[colour
].description
, nics
[card
].description
);
541 strcpy(knics
[colour
].macaddr
, nics
[card
].macaddr
);
543 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
546 errorbox(_("Unable to open settings file"));
550 sprintf(temp1
, "%s_DEV", ucolour
);
551 sprintf(temp2
, "%s_MACADDR", ucolour
);
552 sprintf(temp3
, "%s0", lcolourcard
[colour
]);
553 replacekeyvalue(kv
, temp1
, temp3
);
554 replacekeyvalue(kv
, temp2
, nics
[card
].macaddr
);
555 sprintf(temp1
, "%s_DESCRIPTION", ucolour
);
556 replacekeyvalue(kv
, temp1
, nics
[card
].description
);
557 sprintf(temp1
, "%s_DRIVER", ucolour
);
558 replacekeyvalue(kv
, temp1
, nics
[card
].driver
);
560 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
566 int scan_network_cards(void)
569 char driver
[STRING_SIZE
], description
[STRING_SIZE
], macaddr
[STRING_SIZE
], temp_line
[STRING_SIZE
];
571 const char _driver
[]="driver: ";
572 const char _desc
[]="desc: ";
573 const char _network_hwaddr
[]="network.hwaddr: ";
575 if (!(scanned_nics_read_done
))
577 mysystem(NULL
, "/usr/bin/probenic.sh");
578 if( (fp
= fopen(SCANNED_NICS
, "r")) == NULL
)
580 fprintf(stderr
,"Couldn't open "SCANNED_NICS
);
583 while (fgets(temp_line
, STRING_SIZE
, fp
) != NULL
)
585 temp_line
[strlen(temp_line
) -1] = 0;
586 if ( strncmp(temp_line
, _driver
, strlen(_driver
)) == 0 ) sprintf(nics
[count
].driver
, "%s", temp_line
+strlen(_driver
));
587 if ( strncmp(temp_line
, _desc
, strlen(_desc
)) == 0 ) sprintf(nics
[count
].description
, "%s", temp_line
+strlen(_desc
));
588 if ( strncmp(temp_line
, _network_hwaddr
, strlen(_network_hwaddr
)) == 0 ) sprintf(nics
[count
].macaddr
, "%s", temp_line
+strlen(_network_hwaddr
));
589 if (strlen(nics
[count
].macaddr
) > 15 ) {
590 sprintf(nics
[count
].nic
, "%s", find_nic4mac(nics
[count
].macaddr
));
595 scanned_nics_read_done
= count
;
596 } else fprintf(flog
,"Scan Networkcards does read.\n");
597 return scanned_nics_read_done
;
602 int nicmenu(int colour
)
604 int rc
, choise
= 0, count
= 0, kcount
= 0, mcount
= 0, i
, j
, nic_in_use
;
605 int found_NIC_as_Card
[MAX_NICS
];
606 char message
[STRING_SIZE
];
607 char temp
[STRING_SIZE
];
609 char cMenuInhalt
[STRING_SIZE
];
610 char MenuInhalt
[MAX_NICS
][STRING_SIZE
];
611 char *pMenuInhalt
[MAX_NICS
];
613 while (strcmp(nics
[count
].macaddr
, "")) count
++; // 2 find how many nics in system
614 for (i
=0; i
<MAX_NICS
; i
++) if (strcmp(knics
[i
].macaddr
, "")) kcount
++; // loop to find all knowing nics
616 // If new nics are found...
617 if (count
> kcount
) {
618 for (i
=0 ; i
< count
; i
++)
621 for (j
=0 ; j
<= kcount
; j
++) {
622 if (strcmp(nics
[ i
].macaddr
, knics
[ j
].macaddr
) == 0 ) {
628 if ( strlen(nics
[i
].description
) < 55 )
629 sprintf(MenuInhalt
[mcount
], "%.*s", strlen(nics
[i
].description
)-2, nics
[i
].description
+1);
631 sprintf(cMenuInhalt
, "%.50s", nics
[i
].description
+ 1);
632 sprintf(MenuInhalt
[mcount
], cMenuInhalt
);
633 strcat (MenuInhalt
[mcount
], "...");
636 while ( strlen(MenuInhalt
[mcount
]) < 53) strcat(MenuInhalt
[mcount
], " "); // Fill with space.
638 strcat(MenuInhalt
[mcount
], " (");
639 strcat(MenuInhalt
[mcount
], nics
[i
].macaddr
);
640 strcat(MenuInhalt
[mcount
], ")");
641 pMenuInhalt
[mcount
] = MenuInhalt
[mcount
];
642 found_NIC_as_Card
[mcount
]=i
;
647 pMenuInhalt
[mcount
] = NULL
;
649 sprintf(message
, _("Please choose a networkcard for the following interface - %s."), ucolourcard
[colour
]);
652 rc
= newtWinMenu(_("Extended Network Menu"), message
, 50, 5, 5, mcount
, pMenuInhalt
, &choise
,
653 _("Select"), _("Identify"), _("Cancel"), NULL
);
655 sprintf(temp
, "/sbin/ip link set %s up", nics
[found_NIC_as_Card
[choise
]].nic
);
656 mysystem(NULL
, temp
);
657 sprintf(temp
, "/usr/sbin/ethtool -p %s 10", nics
[found_NIC_as_Card
[choise
]].nic
);
658 if (runcommandwithstatus(temp
, _("Device Identification"), _("The lights on the selected port should flash now for 10 seconds..."), NULL
) != 0) {
659 errorbox(_("Identification is not supported by this interface."));
660 sprintf(temp
, "/sbin/ip link set %s down", nics
[found_NIC_as_Card
[choise
]].nic
);
661 mysystem(NULL
, temp
);
665 if ( rc
== 0 || rc
== 1) {
666 write_configs_netudev(found_NIC_as_Card
[choise
], colour
);
670 // We have to add here that you can manually add a device
671 errorbox(_("There are no unassigned interfaces on your system."));
676 int clear_card_entry(int card
)
678 struct keyvalue
*kv
= initkeyvalues();
679 char temp
[STRING_SIZE
];
681 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
684 errorbox(_("Unable to open settings file"));
688 strcpy(knics
[card
].driver
, "");
689 strcpy(knics
[card
].description
, _("Unset"));
690 strcpy(knics
[card
].macaddr
, "");
691 strcpy(knics
[card
].colour
, "");
692 sprintf(temp
, "%s_DRIVER", ucolourcard
[card
]);
693 replacekeyvalue(kv
, temp
, "");
694 sprintf(temp
, "%s_DEV", ucolourcard
[card
]);
695 replacekeyvalue(kv
, temp
, "");
696 sprintf(temp
, "%s_MACADDR", ucolourcard
[card
]);
697 replacekeyvalue(kv
, temp
, "");
698 sprintf(temp
, "%s_DESCRIPTION", ucolourcard
[card
]);
699 replacekeyvalue(kv
, temp
, "");
701 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
707 int ask_clear_card_entry(int card
)
709 char message
[STRING_SIZE
];
712 sprintf(message
, _("Do you really want to remove the assigned %s interface?"), ucolourcard
[card
]);
713 rc
= newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message
);
715 if ( rc
= 0 || rc
== 1) {
716 clear_card_entry(card
);
722 /* Manual entry for gurus. */
723 int manualdriver(char *driver
, char *driveroptions
)
725 char *values
[] = { NULL
, NULL
}; /* pointers for the values. */
726 struct newtWinEntry entries
[] =
727 { { "", &values
[0], 0,}, { NULL
, NULL
, 0 } };
729 char commandstring
[STRING_SIZE
];
733 strcpy(driveroptions
, "");
735 rc
= newtWinEntries(_("Select network driver"), _("Set additional module parameters"),
736 50, 5, 5, 40, entries
, _("OK"), _("Cancel"), NULL
);
737 if (rc
== 0 || rc
== 1)
739 if (strlen(values
[0]))
741 sprintf(commandstring
, "/sbin/modprobe %s", values
[0]);
742 if (runcommandwithstatus(commandstring
, _("Loading module..."), _("Loading module..."), NULL
) == 0)
744 if ((driverend
= strchr(values
[0], ' ')))
747 strcpy(driver
, values
[0]);
748 strcpy(driveroptions
, driverend
+ 1);
752 strcpy(driver
, values
[0]);
753 strcpy(driveroptions
, "");
757 errorbox(_("Unable to load driver module."));
760 errorbox(_("Module name cannot be blank."));