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"
19 extern struct nic nics
[];
20 extern struct knic knics
[];
22 char *ucolourcard
[] = { "GREEN", "RED", "ORANGE", "BLUE", NULL
};
23 char *lcolourcard
[] = { "green", "red", "orange", "blue", NULL
};
25 int scanned_nics_read_done
= 0;
27 newtComponent networkform
;
28 newtComponent addressentry
;
29 newtComponent netmaskentry
;
30 newtComponent statictyperadio
;
31 newtComponent dhcptyperadio
;
32 newtComponent pppoetyperadio
;
33 newtComponent dhcphostnameentry
;
34 newtComponent dhcpforcemtuentry
;
36 /* acceptable character filter for IP and netmaks entry boxes */
37 static int ip_input_filter(newtComponent entry
, void * data
, int ch
, int cursor
)
39 if ((ch
>= '0' && ch
<= '9') || ch
== '.' || ch
== '\r' || ch
>= NEWT_KEY_EXTRA_BASE
)
44 /* This is a groovie dialog for showing network info. Takes a keyvalue list,
45 * a colour and a dhcp flag. Shows the current settings, and rewrites them
46 * if necessary. DHCP flag sets wether to show the dhcp checkbox. */
47 int changeaddress(struct keyvalue
*kv
, char *colour
, int typeflag
,
48 char *defaultdhcphostname
)
52 char *dhcphostnameresult
;
53 char *dhcpforcemturesult
;
54 struct newtExitStruct es
;
56 newtComponent addresslabel
;
57 newtComponent netmasklabel
;
58 newtComponent dhcphostnamelabel
;
59 newtComponent dhcpforcemtulabel
;
60 newtComponent ok
, cancel
;
62 char temp
[STRING_SIZE
];
63 char addressfield
[STRING_SIZE
];
64 char netmaskfield
[STRING_SIZE
];
65 char typefield
[STRING_SIZE
];
66 char dhcphostnamefield
[STRING_SIZE
];
67 char dhcpforcemtufield
[STRING_SIZE
];
70 char type
[STRING_SIZE
];
71 int startstatictype
= 0;
72 int startdhcptype
= 0;
73 int startpppoetype
= 0;
75 /* Build some key strings. */
76 sprintf(addressfield
, "%s_ADDRESS", colour
);
77 sprintf(netmaskfield
, "%s_NETMASK", colour
);
78 sprintf(typefield
, "%s_TYPE", colour
);
79 sprintf(dhcphostnamefield
, "%s_DHCP_HOSTNAME", colour
);
80 sprintf(dhcpforcemtufield
, "%s_DHCP_FORCE_MTU", colour
);
82 sprintf(message
, ctr
[TR_INTERFACE
], colour
);
83 newtCenteredWindow(44, (typeflag
? 18 : 12), message
);
85 networkform
= newtForm(NULL
, NULL
, 0);
87 sprintf(message
, ctr
[TR_ENTER_THE_IP_ADDRESS_INFORMATION
], colour
);
88 header
= newtTextboxReflowed(1, 1, message
, 42, 0, 0, 0);
89 newtFormAddComponent(networkform
, header
);
91 /* See if we need a dhcp checkbox. If we do, then we shift the contents
92 * of the window down two rows to make room. */
95 strcpy(temp
, "STATIC"); findkey(kv
, typefield
, temp
);
96 if (strcmp(temp
, "STATIC") == 0) startstatictype
= 1;
97 if (strcmp(temp
, "DHCP") == 0) startdhcptype
= 1;
98 if (strcmp(temp
, "PPPOE") == 0) startpppoetype
= 1;
99 statictyperadio
= newtRadiobutton(2, 4, ctr
[TR_STATIC
], startstatictype
, NULL
);
100 dhcptyperadio
= newtRadiobutton(2, 5, ctr
[TR_DHCP
], startdhcptype
, statictyperadio
);
101 pppoetyperadio
= newtRadiobutton(2, 6, ctr
[TR_PPP_DIALUP
], startpppoetype
, dhcptyperadio
);
102 newtFormAddComponents(networkform
, statictyperadio
, dhcptyperadio
,
103 pppoetyperadio
, NULL
);
104 newtComponentAddCallback(statictyperadio
, networkdialogcallbacktype
, NULL
);
105 newtComponentAddCallback(dhcptyperadio
, networkdialogcallbacktype
, NULL
);
106 newtComponentAddCallback(pppoetyperadio
, networkdialogcallbacktype
, NULL
);
107 dhcphostnamelabel
= newtTextbox(2, 8, 18, 1, 0);
108 newtTextboxSetText(dhcphostnamelabel
, ctr
[TR_DHCP_HOSTNAME
]);
109 dhcpforcemtulabel
= newtTextbox(2, 9, 18, 1, 0);
110 newtTextboxSetText(dhcpforcemtulabel
, ctr
[TR_DHCP_FORCE_MTU
]);
111 strcpy(temp
, defaultdhcphostname
);
112 findkey(kv
, dhcphostnamefield
, temp
);
113 dhcphostnameentry
= newtEntry(20, 8, temp
, 20, &dhcphostnameresult
, 0);
115 findkey(kv
, dhcpforcemtufield
, temp
);
116 dhcpforcemtuentry
= newtEntry(20, 9, temp
, 20, &dhcpforcemturesult
, 0);
117 newtFormAddComponent(networkform
, dhcphostnamelabel
);
118 newtFormAddComponent(networkform
, dhcphostnameentry
);
119 newtFormAddComponent(networkform
, dhcpforcemtulabel
);
120 newtFormAddComponent(networkform
, dhcpforcemtuentry
);
121 if (startdhcptype
== 0)
123 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
124 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
128 addresslabel
= newtTextbox(2, (typeflag
? 11 : 4) + 0, 18, 1, 0);
129 newtTextboxSetText(addresslabel
, ctr
[TR_IP_ADDRESS_PROMPT
]);
131 findkey(kv
, addressfield
, temp
);
132 addressentry
= newtEntry(20, (typeflag
? 11 : 4) + 0, temp
, 20, &addressresult
, 0);
133 newtEntrySetFilter(addressentry
, ip_input_filter
, NULL
);
134 if (typeflag
== 1 && startstatictype
== 0)
135 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
136 newtFormAddComponent(networkform
, addresslabel
);
137 newtFormAddComponent(networkform
, addressentry
);
140 netmasklabel
= newtTextbox(2, (typeflag
? 11 : 4) + 1, 18, 1, 0);
141 newtTextboxSetText(netmasklabel
, ctr
[TR_NETMASK_PROMPT
]);
142 strcpy(temp
, "255.255.255.0"); findkey(kv
, netmaskfield
, temp
);
143 netmaskentry
= newtEntry(20, (typeflag
? 11 : 4) + 1, temp
, 20, &netmaskresult
, 0);
144 newtEntrySetFilter(netmaskentry
, ip_input_filter
, NULL
);
145 if (typeflag
== 1 && startstatictype
== 0)
146 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
148 newtFormAddComponent(networkform
, netmasklabel
);
149 newtFormAddComponent(networkform
, netmaskentry
);
152 ok
= newtButton(8, (typeflag
? 14 : 7), ctr
[TR_OK
]);
153 cancel
= newtButton(26, (typeflag
? 14 : 7), ctr
[TR_CANCEL
]);
155 newtFormAddComponents(networkform
, ok
, cancel
, NULL
);
158 newtDrawForm(networkform
);
163 newtFormRun(networkform
, &es
);
167 /* OK was pressed; verify the contents of each entry. */
168 strcpy(message
, ctr
[TR_INVALID_FIELDS
]);
170 strcpy(type
, "STATIC");
173 if (strcmp(type
, "STATIC") == 0)
175 if (inet_addr(addressresult
) == INADDR_NONE
)
177 strcat(message
, ctr
[TR_IP_ADDRESS_CR
]);
180 if (inet_addr(netmaskresult
) == INADDR_NONE
)
182 strcat(message
, ctr
[TR_NETWORK_MASK_CR
]);
186 if (strcmp(type
, "DHCP") == 0)
188 if (!strlen(dhcphostnameresult
))
190 strcat(message
, ctr
[TR_DHCP_HOSTNAME_CR
]);
198 /* No errors! Set new values, depending on dhcp flag etc. */
201 replacekeyvalue(kv
, dhcphostnamefield
, dhcphostnameresult
);
202 replacekeyvalue(kv
, dhcpforcemtufield
, dhcpforcemturesult
);
203 if (strcmp(type
, "STATIC") != 0)
205 replacekeyvalue(kv
, addressfield
, "0.0.0.0");
206 replacekeyvalue(kv
, netmaskfield
, "0.0.0.0");
210 replacekeyvalue(kv
, addressfield
, addressresult
);
211 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
213 replacekeyvalue(kv
, typefield
, type
);
217 replacekeyvalue(kv
, addressfield
, addressresult
);
218 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
221 setnetaddress(kv
, colour
);
225 /* Workaround for a bug that dhcp radiobutton also end the dialog at arm
228 if (es
.u
.co
!= cancel
) {
235 newtFormDestroy(networkform
);
241 /* for pppoe: return string thats type STATIC, DHCP or PPPOE */
242 int gettype(char *type
)
244 newtComponent selected
= newtRadioGetCurrent(statictyperadio
);
246 if (selected
== statictyperadio
)
247 strcpy(type
, "STATIC");
248 else if (selected
== dhcptyperadio
)
249 strcpy(type
, "DHCP");
250 else if (selected
== pppoetyperadio
)
251 strcpy(type
, "PPPOE");
253 strcpy(type
, "ERROR");
258 /* 0.9.9: calculates broadcast too. */
259 int setnetaddress(struct keyvalue
*kv
, char *colour
)
261 char addressfield
[STRING_SIZE
];
262 char netaddressfield
[STRING_SIZE
];
263 char netmaskfield
[STRING_SIZE
];
264 char broadcastfield
[STRING_SIZE
];
265 char address
[STRING_SIZE
];
266 char netmask
[STRING_SIZE
];
267 unsigned long int intaddress
;
268 unsigned long int intnetaddress
;
269 unsigned long int intnetmask
;
270 unsigned long int intbroadcast
;
275 /* Build some key strings. */
276 sprintf(addressfield
, "%s_ADDRESS", colour
);
277 sprintf(netaddressfield
, "%s_NETADDRESS", colour
);
278 sprintf(netmaskfield
, "%s_NETMASK", colour
);
279 sprintf(broadcastfield
, "%s_BROADCAST", colour
);
281 strcpy(address
, ""); findkey(kv
, addressfield
, address
);
282 strcpy(netmask
, ""); findkey(kv
, netmaskfield
, netmask
);
284 /* Calculate netaddress. Messy.. */
285 intaddress
= inet_addr(address
);
286 intnetmask
= inet_addr(netmask
);
288 intnetaddress
= intaddress
& intnetmask
;
289 temp
.s_addr
= intnetaddress
;
290 netaddress
= inet_ntoa(temp
);
292 replacekeyvalue(kv
, netaddressfield
, netaddress
);
294 intbroadcast
= intnetaddress
| ~intnetmask
;
295 temp
.s_addr
= intbroadcast
;
296 broadcast
= inet_ntoa(temp
);
298 replacekeyvalue(kv
, broadcastfield
, broadcast
);
303 /* Called when dhcp flag is toggled. Toggle disabled state of other 3
305 void networkdialogcallbacktype(newtComponent cm
, void *data
)
307 char type
[STRING_SIZE
];
311 if (strcmp(type
, "STATIC") != 0)
313 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
314 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
318 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
319 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
321 if (strcmp(type
, "DHCP") == 0)
323 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
324 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
328 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
329 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
332 newtDrawForm(networkform
);
335 int interfacecheck(struct keyvalue
*kv
, char *colour
)
337 char temp
[STRING_SIZE
];
338 char colourfields
[NETCHANGE_TOTAL
][STRING_SIZE
];
341 sprintf(colourfields
[ADDRESS
], "%s_ADDRESS", colour
);
342 sprintf(colourfields
[NETADDRESS
], "%s_NETADDRESS", colour
);
343 sprintf(colourfields
[NETMASK
], "%s_NETMASK", colour
);
345 for (c
= 0; c
< 3; c
++)
347 strcpy(temp
, ""); findkey(kv
, colourfields
[c
], temp
);
348 if (!(strlen(temp
))) return 0;
353 /* Funky routine for loading all drivers (cept those are already loaded.). */
354 int probecards(char *driver
, char *driveroptions
)
359 int get_knic(int card
) //returns "0" for zero cards or error and "1" card is found.
361 struct keyvalue
*kv
= initkeyvalues();
362 char temp
[STRING_SIZE
], searchstr
[STRING_SIZE
];
365 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
368 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
372 sprintf(searchstr
, "%s_MACADDR", ucolourcard
[card
]);
373 strcpy(temp
, ""); findkey(kv
, searchstr
, temp
);
375 strcpy(knics
[ card
].macaddr
, temp
);
376 strcpy(knics
[ card
].colour
, ucolourcard
[card
]);
378 sprintf(searchstr
, "%s_DESCRIPTION", ucolourcard
[card
]);
379 findkey(kv
, searchstr
, temp
);
380 strcpy(knics
[ card
].description
, temp
);
382 sprintf(searchstr
, "%s_DRIVER", ucolourcard
[card
]);
383 findkey(kv
, searchstr
, temp
);
384 strcpy(knics
[ card
].driver
, temp
);
387 strcpy(knics
[ card
].description
, ctr
[TR_UNSET
]);
398 found
+= get_knic(_GREEN_CARD_
);
399 found
+= get_knic(_RED_CARD_
);
400 found
+= get_knic(_ORANGE_CARD_
);
401 found
+= get_knic(_BLUE_CARD_
);
406 int fmt_exists(const char *fname
) { /* Check if it is any file or directory */
408 if (stat(fname
, &st
) == -1) return 0;
412 int is_interface_up(char *card
) { /* Check if the interface is UP */
413 char temp
[STRING_SIZE
];
415 sprintf(temp
,"ip link show dev %s | grep -q UP", card
);
416 if (mysystem(temp
)) return 0; else return 1;
419 int rename_device(char *old_name
, char *new_name
) {
420 char temp
[STRING_SIZE
];
422 sprintf(temp
,SYSDIR
"/%s", old_name
);
423 if (!(fmt_exists(temp
))) {
424 fprintf(flog
,"Device not found: %s\n",old_name
);
427 sprintf(temp
,"/sbin/ip link set dev %s name %s",old_name
,new_name
);
433 char g_temp
[STRING_SIZE
]="";
434 char* readmac(char *card
) {
436 char temp
[STRING_SIZE
], mac
[20];
438 sprintf(temp
,"/sys/class/net/%s/address",card
);
439 if( (fp
= fopen(temp
, "r")) == NULL
) {
440 fprintf(flog
,"Couldn't open: %s\n",temp
);
450 char* find_nic4mac(char *findmac
) {
452 struct dirent
*dirzeiger
;
453 char temp
[STRING_SIZE
], temp2
[STRING_SIZE
];
455 if((dir
=opendir(SYSDIR
)) == NULL
) {
456 fprintf(flog
,"Fehler bei opendir (find_name4nic) ...\n");
461 while((dirzeiger
=readdir(dir
)) != NULL
) {
462 if(*((*dirzeiger
).d_name
) != '.' & strcmp(((*dirzeiger
).d_name
), "lo") != 0) {
463 sprintf(temp2
, "%s", readmac((*dirzeiger
).d_name
) );
464 if (strcmp(findmac
, temp2
) == 0) {
465 sprintf(temp
,"%s", (*dirzeiger
).d_name
);
471 if(closedir(dir
) == -1) fprintf(flog
,"Fehler beim schliessen von %s\n", SYSDIR
);
472 strcpy(g_temp
, temp
);
476 int nic_shutdown(char *nic
) {
477 char temp
[STRING_SIZE
];
479 sprintf(temp
,"ip link set %s down", nic
);
483 int nic_startup(char *nic
) {
484 char temp
[STRING_SIZE
];
486 sprintf(temp
,"ip link set %s up", nic
);
491 int rename_nics(void) {
493 int fnics
= scan_network_cards();
494 char nic2find
[STRING_SIZE
], temp
[STRING_SIZE
];
497 if (strcmp(knics
[i
].macaddr
, ""))
498 for(j
=0; j
<fnics
; j
++)
499 if(strcmp(knics
[i
].macaddr
, nics
[j
].macaddr
) == 0) {
500 sprintf(nic2find
,"%s0",lcolourcard
[i
]);
501 if(strcmp(nic2find
, nics
[j
].nic
)) {
502 if(is_interface_up(nics
[j
].nic
)) {
503 nic_shutdown(nics
[j
].nic
);
505 sprintf(temp
,SYSDIR
"/%s", nic2find
);
506 if(fmt_exists(temp
)) {
507 for(k
=0; k
<fnics
; k
++)
508 if (strcmp(nics
[k
].nic
, nic2find
) == 0 ) {
509 if(is_interface_up(nics
[k
].nic
)) {
510 nic_shutdown(nics
[k
].nic
);
512 sprintf(temp
,"dummy%i",k
);
513 if (rename_device(nics
[k
].nic
, temp
)) strcpy(nics
[k
].nic
, temp
);
516 if (rename_device(nics
[j
].nic
, nic2find
)) strcpy(nics
[j
].nic
, nic2find
);
521 int create_udev(void)
523 #define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
527 if ( (fp
= fopen(UDEV_NET_CONF
, "w")) == NULL
) {
528 fprintf(stderr
,"Couldn't open" UDEV_NET_CONF
);
532 for (i
= 0 ; i
< 4 ; i
++)
534 if (strcmp(knics
[i
].macaddr
, "")) {
535 fprintf(fp
,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{type}==\"1\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", knics
[i
].macaddr
, lcolourcard
[i
], knics
[i
].description
);
542 int write_configs_netudev(int card
, int colour
)
544 char commandstring
[STRING_SIZE
];
545 struct keyvalue
*kv
= initkeyvalues();
546 char temp1
[STRING_SIZE
], temp2
[STRING_SIZE
], temp3
[STRING_SIZE
];
547 char ucolour
[STRING_SIZE
];
549 sprintf(ucolour
, ucolourcard
[colour
]);
550 strcpy(knics
[colour
].driver
, nics
[card
].driver
);
551 strcpy(knics
[colour
].description
, nics
[card
].description
);
552 strcpy(knics
[colour
].macaddr
, nics
[card
].macaddr
);
554 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
557 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
561 sprintf(temp1
, "%s_DEV", ucolour
);
562 sprintf(temp2
, "%s_MACADDR", ucolour
);
563 sprintf(temp3
, "%s0", lcolourcard
[colour
]);
564 replacekeyvalue(kv
, temp1
, temp3
);
565 replacekeyvalue(kv
, temp2
, nics
[card
].macaddr
);
566 sprintf(temp1
, "%s_DESCRIPTION", ucolour
);
567 replacekeyvalue(kv
, temp1
, nics
[card
].description
);
568 sprintf(temp1
, "%s_DRIVER", ucolour
);
569 replacekeyvalue(kv
, temp1
, nics
[card
].driver
);
571 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
577 int scan_network_cards(void)
580 char driver
[STRING_SIZE
], description
[STRING_SIZE
], macaddr
[STRING_SIZE
], temp_line
[STRING_SIZE
];
582 const char _driver
[]="driver: ";
583 const char _desc
[]="desc: ";
584 const char _network_hwaddr
[]="network.hwaddr: ";
586 if (!(scanned_nics_read_done
))
588 mysystem("/bin/probenic.sh");
589 if( (fp
= fopen(SCANNED_NICS
, "r")) == NULL
)
591 fprintf(stderr
,"Couldn't open "SCANNED_NICS
);
594 while (fgets(temp_line
, STRING_SIZE
, fp
) != NULL
)
596 temp_line
[strlen(temp_line
) -1] = 0;
597 if ( strncmp(temp_line
, _driver
, strlen(_driver
)) == 0 ) sprintf(nics
[count
].driver
, "%s", temp_line
+strlen(_driver
));
598 if ( strncmp(temp_line
, _desc
, strlen(_desc
)) == 0 ) sprintf(nics
[count
].description
, "%s", temp_line
+strlen(_desc
));
599 if ( strncmp(temp_line
, _network_hwaddr
, strlen(_network_hwaddr
)) == 0 ) sprintf(nics
[count
].macaddr
, "%s", temp_line
+strlen(_network_hwaddr
));
600 if (strlen(nics
[count
].macaddr
) > 15 ) {
601 sprintf(nics
[count
].nic
, "%s", find_nic4mac(nics
[count
].macaddr
));
606 scanned_nics_read_done
= count
;
607 } else fprintf(flog
,"Scan Networkcards does read.\n");
608 return scanned_nics_read_done
;
613 int nicmenu(int colour
)
615 int rc
, choise
= 0, count
= 0, kcount
= 0, mcount
= 0, i
, j
, nic_in_use
;
616 int found_NIC_as_Card
[4];
617 char message
[STRING_SIZE
];
618 char temp
[STRING_SIZE
];
620 char cMenuInhalt
[STRING_SIZE
];
621 char MenuInhalt
[20][180];
622 char *pMenuInhalt
[20];
624 while (strcmp(nics
[count
].macaddr
, "")) count
++; // 2 find how many nics in system
625 for ( i
=0 ; i
<4;i
++) if (strcmp(knics
[i
].macaddr
, "")) kcount
++; // loop to find all knowing nics
627 // If new nics are found...
628 if (count
> kcount
) {
629 for (i
=0 ; i
< count
; i
++)
632 for (j
=0 ; j
<= kcount
; j
++) {
633 if (strcmp(nics
[ i
].macaddr
, knics
[ j
].macaddr
) == 0 ) {
639 if ( strlen(nics
[i
].description
) < 55 )
640 sprintf(MenuInhalt
[mcount
], "%.*s", strlen(nics
[i
].description
)-2, nics
[i
].description
+1);
642 sprintf(cMenuInhalt
, "%.50s", nics
[i
].description
+ 1);
643 sprintf(MenuInhalt
[mcount
], cMenuInhalt
);
644 strcat (MenuInhalt
[mcount
], "...");
647 while ( strlen(MenuInhalt
[mcount
]) < 53) strcat(MenuInhalt
[mcount
], " "); // Fill with space.
649 strcat(MenuInhalt
[mcount
], " (");
650 strcat(MenuInhalt
[mcount
], nics
[i
].macaddr
);
651 strcat(MenuInhalt
[mcount
], ")");
652 pMenuInhalt
[mcount
] = MenuInhalt
[mcount
];
653 found_NIC_as_Card
[mcount
]=i
;
658 pMenuInhalt
[mcount
] = NULL
;
660 sprintf(message
, ctr
[TR_CHOOSE_NETCARD
], ucolourcard
[colour
]);
663 rc
= newtWinMenu( ctr
[TR_NETCARDMENU2
], message
, 50, 5, 5, 6, pMenuInhalt
, &choise
, ctr
[TR_SELECT
], ctr
[TR_IDENTIFY
], ctr
[TR_CANCEL
], NULL
);
665 sprintf(temp
, "/sbin/ip link set %s up", nics
[found_NIC_as_Card
[choise
]].nic
);
667 sprintf(temp
, "/usr/sbin/ethtool -p %s 10", nics
[found_NIC_as_Card
[choise
]].nic
);
668 if (runcommandwithstatus(temp
,ctr
[TR_IDENTIFY_SHOULD_BLINK
]) != 0) {
669 errorbox(ctr
[TR_IDENTIFY_NOT_SUPPORTED
]);
670 sprintf(temp
, "/sbin/ip link set %s down", nics
[found_NIC_as_Card
[choise
]].nic
);
675 if ( rc
== 0 || rc
== 1) {
676 write_configs_netudev(found_NIC_as_Card
[choise
], colour
);
680 // We have to add here that you can manually add a device
681 errorbox( ctr
[TR_ERROR_INTERFACES
]);
686 int clear_card_entry(int card
)
688 struct keyvalue
*kv
= initkeyvalues();
689 char temp
[STRING_SIZE
];
691 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
694 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
698 strcpy(knics
[card
].driver
, "");
699 strcpy(knics
[card
].description
, ctr
[TR_UNSET
]);
700 strcpy(knics
[card
].macaddr
, "");
701 strcpy(knics
[card
].colour
, "");
702 sprintf(temp
, "%s_DRIVER", ucolourcard
[card
]);
703 replacekeyvalue(kv
, temp
, "");
704 sprintf(temp
, "%s_DEV", ucolourcard
[card
]);
705 replacekeyvalue(kv
, temp
, "");
706 sprintf(temp
, "%s_MACADDR", ucolourcard
[card
]);
707 replacekeyvalue(kv
, temp
, "");
708 sprintf(temp
, "%s_DESCRIPTION", ucolourcard
[card
]);
709 replacekeyvalue(kv
, temp
, "");
711 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
717 int ask_clear_card_entry(int card
)
719 char message
[STRING_SIZE
];
722 sprintf(message
, ctr
[TR_REMOVE_CARD
], ucolourcard
[card
]);
723 rc
= newtWinChoice(ctr
[TR_WARNING
], ctr
[TR_OK
], ctr
[TR_CANCEL
], message
);
725 if ( rc
= 0 || rc
== 1) {
726 clear_card_entry(card
);
732 /* Manual entry for gurus. */
733 int manualdriver(char *driver
, char *driveroptions
)
735 char *values
[] = { NULL
, NULL
}; /* pointers for the values. */
736 struct newtWinEntry entries
[] =
737 { { "", &values
[0], 0,}, { NULL
, NULL
, 0 } };
739 char commandstring
[STRING_SIZE
];
743 strcpy(driveroptions
, "");
745 rc
= newtWinEntries(ctr
[TR_SELECT_NETWORK_DRIVER
],
746 ctr
[TR_MODULE_PARAMETERS
], 50, 5, 5, 40, entries
,
747 ctr
[TR_OK
], ctr
[TR_CANCEL
], NULL
);
748 if (rc
== 0 || rc
== 1)
750 if (strlen(values
[0]))
752 sprintf(commandstring
, "/sbin/modprobe %s", values
[0]);
753 if (runcommandwithstatus(commandstring
, ctr
[TR_LOADING_MODULE
]) == 0)
755 if ((driverend
= strchr(values
[0], ' ')))
758 strcpy(driver
, values
[0]);
759 strcpy(driveroptions
, driverend
+ 1);
763 strcpy(driver
, values
[0]);
764 strcpy(driveroptions
, "");
768 errorbox(ctr
[TR_UNABLE_TO_LOAD_DRIVER_MODULE
]);
771 errorbox(ctr
[TR_MODULE_NAME_CANNOT_BE_BLANK
]);