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;
79 /* Build some key strings. */
80 sprintf(addressfield
, "%s_ADDRESS", colour
);
81 sprintf(netmaskfield
, "%s_NETMASK", colour
);
82 sprintf(typefield
, "%s_TYPE", colour
);
83 sprintf(dhcphostnamefield
, "%s_DHCP_HOSTNAME", colour
);
84 sprintf(dhcpforcemtufield
, "%s_DHCP_FORCE_MTU", colour
);
86 sprintf(message
, _("Interface - %s"), colour
);
87 newtCenteredWindow(44, (typeflag
? 18 : 12), message
);
89 networkform
= newtForm(NULL
, NULL
, 0);
91 sprintf(message
, _("Enter the IP address information for the %s interface."), colour
);
92 header
= newtTextboxReflowed(1, 1, message
, 42, 0, 0, 0);
93 newtFormAddComponent(networkform
, header
);
95 /* See if we need a dhcp checkbox. If we do, then we shift the contents
96 * of the window down two rows to make room. */
99 strcpy(temp
, "STATIC"); findkey(kv
, typefield
, temp
);
100 if (strcmp(temp
, "STATIC") == 0) startstatictype
= 1;
101 if (strcmp(temp
, "DHCP") == 0) startdhcptype
= 1;
102 if (strcmp(temp
, "PPPOE") == 0) startpppoetype
= 1;
103 statictyperadio
= newtRadiobutton(2, 4, _("Static"), startstatictype
, NULL
);
104 dhcptyperadio
= newtRadiobutton(2, 5, _("DHCP"), startdhcptype
, statictyperadio
);
105 pppoetyperadio
= newtRadiobutton(2, 6, _("PPP DIALUP (PPPoE, modem, ATM ...)"),
106 startpppoetype
, dhcptyperadio
);
107 newtFormAddComponents(networkform
, statictyperadio
, dhcptyperadio
,
108 pppoetyperadio
, NULL
);
109 newtComponentAddCallback(statictyperadio
, networkdialogcallbacktype
, NULL
);
110 newtComponentAddCallback(dhcptyperadio
, networkdialogcallbacktype
, NULL
);
111 newtComponentAddCallback(pppoetyperadio
, networkdialogcallbacktype
, NULL
);
112 dhcphostnamelabel
= newtTextbox(2, 8, 18, 1, 0);
113 newtTextboxSetText(dhcphostnamelabel
, _("DHCP Hostname:"));
114 dhcpforcemtulabel
= newtTextbox(2, 9, 18, 1, 0);
115 newtTextboxSetText(dhcpforcemtulabel
, _("Force DHCP MTU:"));
116 strcpy(temp
, defaultdhcphostname
);
117 findkey(kv
, dhcphostnamefield
, temp
);
118 dhcphostnameentry
= newtEntry(20, 8, temp
, 20, &dhcphostnameresult
, 0);
120 findkey(kv
, dhcpforcemtufield
, temp
);
121 dhcpforcemtuentry
= newtEntry(20, 9, temp
, 20, &dhcpforcemturesult
, 0);
122 newtFormAddComponent(networkform
, dhcphostnamelabel
);
123 newtFormAddComponent(networkform
, dhcphostnameentry
);
124 newtFormAddComponent(networkform
, dhcpforcemtulabel
);
125 newtFormAddComponent(networkform
, dhcpforcemtuentry
);
126 if (startdhcptype
== 0)
128 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
129 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
133 addresslabel
= newtTextbox(2, (typeflag
? 11 : 4) + 0, 18, 1, 0);
134 newtTextboxSetText(addresslabel
, _("IP address:"));
136 findkey(kv
, addressfield
, temp
);
137 addressentry
= newtEntry(20, (typeflag
? 11 : 4) + 0, temp
, 20, &addressresult
, 0);
138 newtEntrySetFilter(addressentry
, ip_input_filter
, NULL
);
139 if (typeflag
== 1 && startstatictype
== 0)
140 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
141 newtFormAddComponent(networkform
, addresslabel
);
142 newtFormAddComponent(networkform
, addressentry
);
145 netmasklabel
= newtTextbox(2, (typeflag
? 11 : 4) + 1, 18, 1, 0);
146 newtTextboxSetText(netmasklabel
, _("Network mask:"));
147 strcpy(temp
, "255.255.255.0"); findkey(kv
, netmaskfield
, temp
);
148 netmaskentry
= newtEntry(20, (typeflag
? 11 : 4) + 1, temp
, 20, &netmaskresult
, 0);
149 newtEntrySetFilter(netmaskentry
, ip_input_filter
, NULL
);
150 if (typeflag
== 1 && startstatictype
== 0)
151 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
153 newtFormAddComponent(networkform
, netmasklabel
);
154 newtFormAddComponent(networkform
, netmaskentry
);
157 ok
= newtButton(8, (typeflag
? 14 : 7), _("OK"));
158 cancel
= newtButton(26, (typeflag
? 14 : 7), _("Cancel"));
160 newtFormAddComponents(networkform
, ok
, cancel
, NULL
);
163 newtDrawForm(networkform
);
168 newtFormRun(networkform
, &es
);
172 /* OK was pressed; verify the contents of each entry. */
173 strcpy(message
, _("The following fields are invalid:"));
174 strcat(message
, "\n\n");
176 strcpy(type
, "STATIC");
179 if (strcmp(type
, "STATIC") == 0)
181 if (inet_addr(addressresult
) == INADDR_NONE
)
183 strcat(message
, _("IP address"));
184 strcat(message
, "\n");
187 if (inet_addr(netmaskresult
) == INADDR_NONE
)
189 strcat(message
, _("Network mask"));
190 strcat(message
, "\n");
194 if (strcmp(type
, "DHCP") == 0)
196 if (!strlen(dhcphostnameresult
))
198 strcat(message
, _("DHCP hostname"));
199 strcat(message
, "\n");
207 /* No errors! Set new values, depending on dhcp flag etc. */
210 replacekeyvalue(kv
, dhcphostnamefield
, dhcphostnameresult
);
211 replacekeyvalue(kv
, dhcpforcemtufield
, dhcpforcemturesult
);
212 if (strcmp(type
, "STATIC") != 0)
214 replacekeyvalue(kv
, addressfield
, "0.0.0.0");
215 replacekeyvalue(kv
, netmaskfield
, "0.0.0.0");
219 replacekeyvalue(kv
, addressfield
, addressresult
);
220 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
222 replacekeyvalue(kv
, typefield
, type
);
226 replacekeyvalue(kv
, addressfield
, addressresult
);
227 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
230 setnetaddress(kv
, colour
);
234 /* Workaround for a bug that dhcp radiobutton also end the dialog at arm
237 if (es
.u
.co
!= cancel
) {
244 newtFormDestroy(networkform
);
250 /* for pppoe: return string thats type STATIC, DHCP or PPPOE */
251 int gettype(char *type
)
253 newtComponent selected
= newtRadioGetCurrent(statictyperadio
);
255 if (selected
== statictyperadio
)
256 strcpy(type
, "STATIC");
257 else if (selected
== dhcptyperadio
)
258 strcpy(type
, "DHCP");
259 else if (selected
== pppoetyperadio
)
260 strcpy(type
, "PPPOE");
262 strcpy(type
, "ERROR");
267 /* 0.9.9: calculates broadcast too. */
268 int setnetaddress(struct keyvalue
*kv
, char *colour
)
270 char addressfield
[STRING_SIZE
];
271 char netaddressfield
[STRING_SIZE
];
272 char netmaskfield
[STRING_SIZE
];
273 char broadcastfield
[STRING_SIZE
];
274 char address
[STRING_SIZE
];
275 char netmask
[STRING_SIZE
];
276 unsigned long int intaddress
;
277 unsigned long int intnetaddress
;
278 unsigned long int intnetmask
;
279 unsigned long int intbroadcast
;
284 /* Build some key strings. */
285 sprintf(addressfield
, "%s_ADDRESS", colour
);
286 sprintf(netaddressfield
, "%s_NETADDRESS", colour
);
287 sprintf(netmaskfield
, "%s_NETMASK", colour
);
288 sprintf(broadcastfield
, "%s_BROADCAST", colour
);
290 strcpy(address
, ""); findkey(kv
, addressfield
, address
);
291 strcpy(netmask
, ""); findkey(kv
, netmaskfield
, netmask
);
293 /* Calculate netaddress. Messy.. */
294 intaddress
= inet_addr(address
);
295 intnetmask
= inet_addr(netmask
);
297 intnetaddress
= intaddress
& intnetmask
;
298 temp
.s_addr
= intnetaddress
;
299 netaddress
= inet_ntoa(temp
);
301 replacekeyvalue(kv
, netaddressfield
, netaddress
);
303 intbroadcast
= intnetaddress
| ~intnetmask
;
304 temp
.s_addr
= intbroadcast
;
305 broadcast
= inet_ntoa(temp
);
307 replacekeyvalue(kv
, broadcastfield
, broadcast
);
312 /* Called when dhcp flag is toggled. Toggle disabled state of other 3
314 void networkdialogcallbacktype(newtComponent cm
, void *data
)
316 char type
[STRING_SIZE
];
320 if (strcmp(type
, "STATIC") != 0)
322 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
323 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
327 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
328 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
330 if (strcmp(type
, "DHCP") == 0)
332 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
333 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
337 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
338 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
341 newtDrawForm(networkform
);
344 int interfacecheck(struct keyvalue
*kv
, char *colour
)
346 char temp
[STRING_SIZE
];
347 char colourfields
[NETCHANGE_TOTAL
][STRING_SIZE
];
350 sprintf(colourfields
[ADDRESS
], "%s_ADDRESS", colour
);
351 sprintf(colourfields
[NETADDRESS
], "%s_NETADDRESS", colour
);
352 sprintf(colourfields
[NETMASK
], "%s_NETMASK", colour
);
354 for (c
= 0; c
< 3; c
++)
356 strcpy(temp
, ""); findkey(kv
, colourfields
[c
], temp
);
357 if (!(strlen(temp
))) return 0;
362 /* Funky routine for loading all drivers (cept those are already loaded.). */
363 int probecards(char *driver
, char *driveroptions
)
368 int get_knic(int card
) //returns "0" for zero cards or error and "1" card is found.
370 struct keyvalue
*kv
= initkeyvalues();
371 char temp
[STRING_SIZE
], searchstr
[STRING_SIZE
];
374 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
377 errorbox(_("Unable to open settings file"));
381 sprintf(searchstr
, "%s_MACADDR", ucolourcard
[card
]);
382 strcpy(temp
, ""); findkey(kv
, searchstr
, temp
);
384 strcpy(knics
[ card
].macaddr
, temp
);
385 strcpy(knics
[ card
].colour
, ucolourcard
[card
]);
387 sprintf(searchstr
, "%s_DESCRIPTION", ucolourcard
[card
]);
388 findkey(kv
, searchstr
, temp
);
389 strcpy(knics
[ card
].description
, temp
);
391 sprintf(searchstr
, "%s_DRIVER", ucolourcard
[card
]);
392 findkey(kv
, searchstr
, temp
);
393 strcpy(knics
[ card
].driver
, temp
);
396 strcpy(knics
[ card
].description
, _("Unset"));
407 found
+= get_knic(_GREEN_CARD_
);
408 found
+= get_knic(_RED_CARD_
);
409 found
+= get_knic(_ORANGE_CARD_
);
410 found
+= get_knic(_BLUE_CARD_
);
415 int fmt_exists(const char *fname
) { /* Check if it is any file or directory */
417 if (stat(fname
, &st
) == -1) return 0;
421 int is_interface_up(char *card
) { /* Check if the interface is UP */
422 char temp
[STRING_SIZE
];
424 sprintf(temp
,"ip link show dev %s | grep -q UP", card
);
425 if (mysystem(NULL
, temp
)) return 0; else return 1;
428 int rename_device(char *old_name
, char *new_name
) {
429 char temp
[STRING_SIZE
];
431 sprintf(temp
,SYSDIR
"/%s", old_name
);
432 if (!(fmt_exists(temp
))) {
433 fprintf(flog
,"Device not found: %s\n",old_name
);
436 sprintf(temp
,"/sbin/ip link set dev %s name %s",old_name
,new_name
);
437 mysystem(NULL
, temp
);
442 char g_temp
[STRING_SIZE
]="";
443 char* readmac(char *card
) {
445 char temp
[STRING_SIZE
], mac
[20];
447 sprintf(temp
,"/sys/class/net/%s/address",card
);
448 if( (fp
= fopen(temp
, "r")) == NULL
) {
449 fprintf(flog
,"Couldn't open: %s\n",temp
);
459 char* find_nic4mac(char *findmac
) {
461 struct dirent
*dirzeiger
;
462 char temp
[STRING_SIZE
], temp2
[STRING_SIZE
];
464 if((dir
=opendir(SYSDIR
)) == NULL
) {
465 fprintf(flog
,"Fehler bei opendir (find_name4nic) ...\n");
470 while((dirzeiger
=readdir(dir
)) != NULL
) {
471 if(*((*dirzeiger
).d_name
) != '.' & strcmp(((*dirzeiger
).d_name
), "lo") != 0) {
472 sprintf(temp2
, "%s", readmac((*dirzeiger
).d_name
) );
473 if (strcmp(findmac
, temp2
) == 0) {
474 sprintf(temp
,"%s", (*dirzeiger
).d_name
);
480 if(closedir(dir
) == -1) fprintf(flog
,"Fehler beim schliessen von %s\n", SYSDIR
);
481 strcpy(g_temp
, temp
);
485 int nic_shutdown(char *nic
) {
486 char temp
[STRING_SIZE
];
488 sprintf(temp
,"ip link set %s down", nic
);
489 mysystem(NULL
, temp
);
492 int nic_startup(char *nic
) {
493 char temp
[STRING_SIZE
];
495 sprintf(temp
,"ip link set %s up", nic
);
496 mysystem(NULL
, temp
);
500 int rename_nics(void) {
502 int fnics
= scan_network_cards();
503 char nic2find
[STRING_SIZE
], temp
[STRING_SIZE
];
506 if (strcmp(knics
[i
].macaddr
, ""))
507 for(j
=0; j
<fnics
; j
++)
508 if(strcmp(knics
[i
].macaddr
, nics
[j
].macaddr
) == 0) {
509 sprintf(nic2find
,"%s0",lcolourcard
[i
]);
510 if(strcmp(nic2find
, nics
[j
].nic
)) {
511 if(is_interface_up(nics
[j
].nic
)) {
512 nic_shutdown(nics
[j
].nic
);
514 sprintf(temp
,SYSDIR
"/%s", nic2find
);
515 if(fmt_exists(temp
)) {
516 for(k
=0; k
<fnics
; k
++)
517 if (strcmp(nics
[k
].nic
, nic2find
) == 0 ) {
518 if(is_interface_up(nics
[k
].nic
)) {
519 nic_shutdown(nics
[k
].nic
);
521 sprintf(temp
,"dummy%i",k
);
522 if (rename_device(nics
[k
].nic
, temp
)) strcpy(nics
[k
].nic
, temp
);
525 if (rename_device(nics
[j
].nic
, nic2find
)) strcpy(nics
[j
].nic
, nic2find
);
530 int create_udev(void)
532 #define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
536 if ( (fp
= fopen(UDEV_NET_CONF
, "w")) == NULL
) {
537 fprintf(stderr
,"Couldn't open" UDEV_NET_CONF
);
541 for (i
= 0 ; i
< 4 ; i
++)
543 if (strcmp(knics
[i
].macaddr
, "")) {
544 fprintf(fp
,"\n# %s\nACTION==\"add\", SUBSYSTEM==\"net\", ATTR{type}==\"1\", ATTR{address}==\"%s\", NAME=\"%s0\"\n", knics
[i
].description
, knics
[i
].macaddr
, lcolourcard
[i
]);
551 int write_configs_netudev(int card
, int colour
)
553 char commandstring
[STRING_SIZE
];
554 struct keyvalue
*kv
= initkeyvalues();
555 char temp1
[STRING_SIZE
], temp2
[STRING_SIZE
], temp3
[STRING_SIZE
];
556 char ucolour
[STRING_SIZE
];
558 sprintf(ucolour
, ucolourcard
[colour
]);
559 strcpy(knics
[colour
].driver
, nics
[card
].driver
);
560 strcpy(knics
[colour
].description
, nics
[card
].description
);
561 strcpy(knics
[colour
].macaddr
, nics
[card
].macaddr
);
563 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
566 errorbox(_("Unable to open settings file"));
570 sprintf(temp1
, "%s_DEV", ucolour
);
571 sprintf(temp2
, "%s_MACADDR", ucolour
);
572 sprintf(temp3
, "%s0", lcolourcard
[colour
]);
573 replacekeyvalue(kv
, temp1
, temp3
);
574 replacekeyvalue(kv
, temp2
, nics
[card
].macaddr
);
575 sprintf(temp1
, "%s_DESCRIPTION", ucolour
);
576 replacekeyvalue(kv
, temp1
, nics
[card
].description
);
577 sprintf(temp1
, "%s_DRIVER", ucolour
);
578 replacekeyvalue(kv
, temp1
, nics
[card
].driver
);
580 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
586 int scan_network_cards(void)
589 char driver
[STRING_SIZE
], description
[STRING_SIZE
], macaddr
[STRING_SIZE
], temp_line
[STRING_SIZE
];
591 const char _driver
[]="driver: ";
592 const char _desc
[]="desc: ";
593 const char _network_hwaddr
[]="network.hwaddr: ";
595 if (!(scanned_nics_read_done
))
597 mysystem(NULL
, "/usr/bin/probenic.sh");
598 if( (fp
= fopen(SCANNED_NICS
, "r")) == NULL
)
600 fprintf(stderr
,"Couldn't open "SCANNED_NICS
);
603 while (fgets(temp_line
, STRING_SIZE
, fp
) != NULL
)
605 temp_line
[strlen(temp_line
) -1] = 0;
606 if ( strncmp(temp_line
, _driver
, strlen(_driver
)) == 0 ) sprintf(nics
[count
].driver
, "%s", temp_line
+strlen(_driver
));
607 if ( strncmp(temp_line
, _desc
, strlen(_desc
)) == 0 ) sprintf(nics
[count
].description
, "%s", temp_line
+strlen(_desc
));
608 if ( strncmp(temp_line
, _network_hwaddr
, strlen(_network_hwaddr
)) == 0 ) sprintf(nics
[count
].macaddr
, "%s", temp_line
+strlen(_network_hwaddr
));
609 if (strlen(nics
[count
].macaddr
) > 15 ) {
610 sprintf(nics
[count
].nic
, "%s", find_nic4mac(nics
[count
].macaddr
));
615 scanned_nics_read_done
= count
;
616 } else fprintf(flog
,"Scan Networkcards does read.\n");
617 return scanned_nics_read_done
;
622 int nicmenu(int colour
)
624 int rc
, choise
= 0, count
= 0, kcount
= 0, mcount
= 0, i
, j
, nic_in_use
;
625 int found_NIC_as_Card
[4];
626 char message
[STRING_SIZE
];
627 char temp
[STRING_SIZE
];
629 char cMenuInhalt
[STRING_SIZE
];
630 char MenuInhalt
[20][180];
631 char *pMenuInhalt
[20];
633 while (strcmp(nics
[count
].macaddr
, "")) count
++; // 2 find how many nics in system
634 for ( i
=0 ; i
<4;i
++) if (strcmp(knics
[i
].macaddr
, "")) kcount
++; // loop to find all knowing nics
636 // If new nics are found...
637 if (count
> kcount
) {
638 for (i
=0 ; i
< count
; i
++)
641 for (j
=0 ; j
<= kcount
; j
++) {
642 if (strcmp(nics
[ i
].macaddr
, knics
[ j
].macaddr
) == 0 ) {
648 if ( strlen(nics
[i
].description
) < 55 )
649 sprintf(MenuInhalt
[mcount
], "%.*s", strlen(nics
[i
].description
)-2, nics
[i
].description
+1);
651 sprintf(cMenuInhalt
, "%.50s", nics
[i
].description
+ 1);
652 sprintf(MenuInhalt
[mcount
], cMenuInhalt
);
653 strcat (MenuInhalt
[mcount
], "...");
656 while ( strlen(MenuInhalt
[mcount
]) < 53) strcat(MenuInhalt
[mcount
], " "); // Fill with space.
658 strcat(MenuInhalt
[mcount
], " (");
659 strcat(MenuInhalt
[mcount
], nics
[i
].macaddr
);
660 strcat(MenuInhalt
[mcount
], ")");
661 pMenuInhalt
[mcount
] = MenuInhalt
[mcount
];
662 found_NIC_as_Card
[mcount
]=i
;
667 pMenuInhalt
[mcount
] = NULL
;
669 sprintf(message
, _("Please choose a networkcard for the following interface - %s."), ucolourcard
[colour
]);
672 rc
= newtWinMenu(_("Extended Network Menu"), message
, 50, 5, 5, 6, pMenuInhalt
, &choise
,
673 _("Select"), _("Identify"), _("Cancel"), NULL
);
675 sprintf(temp
, "/sbin/ip link set %s up", nics
[found_NIC_as_Card
[choise
]].nic
);
676 mysystem(NULL
, temp
);
677 sprintf(temp
, "/usr/sbin/ethtool -p %s 10", nics
[found_NIC_as_Card
[choise
]].nic
);
678 if (runcommandwithstatus(temp
, _("Device Identification"), _("The lights on the selected port should flash now for 10 seconds..."), NULL
) != 0) {
679 errorbox(_("Identification is not supported by this interface."));
680 sprintf(temp
, "/sbin/ip link set %s down", nics
[found_NIC_as_Card
[choise
]].nic
);
681 mysystem(NULL
, temp
);
685 if ( rc
== 0 || rc
== 1) {
686 write_configs_netudev(found_NIC_as_Card
[choise
], colour
);
690 // We have to add here that you can manually add a device
691 errorbox(_("There are no unassigned interfaces on your system."));
696 int clear_card_entry(int card
)
698 struct keyvalue
*kv
= initkeyvalues();
699 char temp
[STRING_SIZE
];
701 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
704 errorbox(_("Unable to open settings file"));
708 strcpy(knics
[card
].driver
, "");
709 strcpy(knics
[card
].description
, _("Unset"));
710 strcpy(knics
[card
].macaddr
, "");
711 strcpy(knics
[card
].colour
, "");
712 sprintf(temp
, "%s_DRIVER", ucolourcard
[card
]);
713 replacekeyvalue(kv
, temp
, "");
714 sprintf(temp
, "%s_DEV", ucolourcard
[card
]);
715 replacekeyvalue(kv
, temp
, "");
716 sprintf(temp
, "%s_MACADDR", ucolourcard
[card
]);
717 replacekeyvalue(kv
, temp
, "");
718 sprintf(temp
, "%s_DESCRIPTION", ucolourcard
[card
]);
719 replacekeyvalue(kv
, temp
, "");
721 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
727 int ask_clear_card_entry(int card
)
729 char message
[STRING_SIZE
];
732 sprintf(message
, _("Do you really want to remove the assigned %s interface?"), ucolourcard
[card
]);
733 rc
= newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message
);
735 if ( rc
= 0 || rc
== 1) {
736 clear_card_entry(card
);
742 /* Manual entry for gurus. */
743 int manualdriver(char *driver
, char *driveroptions
)
745 char *values
[] = { NULL
, NULL
}; /* pointers for the values. */
746 struct newtWinEntry entries
[] =
747 { { "", &values
[0], 0,}, { NULL
, NULL
, 0 } };
749 char commandstring
[STRING_SIZE
];
753 strcpy(driveroptions
, "");
755 rc
= newtWinEntries(_("Select network driver"), _("Set additional module parameters"),
756 50, 5, 5, 40, entries
, _("OK"), _("Cancel"), NULL
);
757 if (rc
== 0 || rc
== 1)
759 if (strlen(values
[0]))
761 sprintf(commandstring
, "/sbin/modprobe %s", values
[0]);
762 if (runcommandwithstatus(commandstring
, _("Loading module..."), _("Loading module..."), NULL
) == 0)
764 if ((driverend
= strchr(values
[0], ' ')))
767 strcpy(driver
, values
[0]);
768 strcpy(driveroptions
, driverend
+ 1);
772 strcpy(driver
, values
[0]);
773 strcpy(driveroptions
, "");
777 errorbox(_("Unable to load driver module."));
780 errorbox(_("Module name cannot be blank."));