net-setup: Add routing and old stack's configuration

This allows the old stack's configuration structures to be used
unchanged even though this code currently does not support all
of the options. It likely will never support all of the options
as some should eventually come through configuration files as
they would in a real FreeBSD system. Other configuration
parameters are likely configurable via "hints".
This commit is contained in:
Joel Sherrill 2012-07-27 07:45:06 -05:00
parent 4a3e48913b
commit bd6dd6e233
3 changed files with 95 additions and 42 deletions

View File

@ -7,6 +7,7 @@ include $(PROJECT_ROOT)/make/leaf.cfg
CFLAGS += -I $(INSTALL_BASE)/include CFLAGS += -I $(INSTALL_BASE)/include
#CFLAGS += -ffreestanding #CFLAGS += -ffreestanding
CFLAGS += -I include CFLAGS += -I include
CFLAGS += -I rtems/include
CFLAGS += -I lib/libc/include CFLAGS += -I lib/libc/include
CFLAGS += -I sys CFLAGS += -I sys
CFLAGS += -I local CFLAGS += -I local
@ -108,6 +109,8 @@ install: $(LIB)
install -d $(INSTALL_BASE)/include install -d $(INSTALL_BASE)/include
cd include; for i in `find . -name '*.h'` ; do \ cd include; for i in `find . -name '*.h'` ; do \
install -c -m 644 -D "$$i" "$(INSTALL_BASE)/include/$$i" ; done install -c -m 644 -D "$$i" "$(INSTALL_BASE)/include/$$i" ; done
cd rtems/include; for i in `find . -name '*.h'` ; do \
install -c -m 644 -D "$$i" "$(INSTALL_BASE)/include/$$i" ; done
install -c -m 644 $(LIB) $(INSTALL_BASE) install -c -m 644 $(LIB) $(INSTALL_BASE)
clean: clean:

View File

@ -9,6 +9,8 @@
#include <net/if.h> #include <net/if.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <net/route.h>
#include <rtems/rtems_bsdnet.h>
static const struct sockaddr_in address_template = { static const struct sockaddr_in address_template = {
sizeof(address_template), sizeof(address_template),
@ -18,6 +20,30 @@ static const struct sockaddr_in address_template = {
{ 0, 0, 0, 0, 0, 0, 0, 0 } { 0, 0, 0, 0, 0, 0, 0, 0 }
}; };
/*
* Manipulate routing tables
*/
int rtems_bsdnet_rtrequest(
int req,
struct sockaddr *dst,
struct sockaddr *gateway,
struct sockaddr *netmask,
int flags,
struct rtentry **net_nrt
)
{
int error;
// rtems_bsdnet_semaphore_obtain();
error = rtrequest(req, dst, gateway, netmask, flags, net_nrt);
// rtems_bsdnet_semaphore_release();
if (error) {
errno = error;
return -1;
}
return 0;
}
static void static void
rtems_bsdnet_initialize_sockaddr_in(struct sockaddr_in *addr) rtems_bsdnet_initialize_sockaddr_in(struct sockaddr_in *addr)
{ {
@ -235,6 +261,7 @@ static bool rtems_bsdnet_setup_interface(
void rtems_initialize_interfaces(void) void rtems_initialize_interfaces(void)
{ {
bool any_if_configured; bool any_if_configured;
struct rtems_bsdnet_ifconfig *ifp;
any_if_configured = false; any_if_configured = false;
@ -244,7 +271,6 @@ void rtems_initialize_interfaces(void)
"255.0.0.0" "255.0.0.0"
); );
#if 0
for (ifp = rtems_bsdnet_config.ifconfig ; ifp ; ifp = ifp->next) { for (ifp = rtems_bsdnet_config.ifconfig ; ifp ; ifp = ifp->next) {
if (ifp->ip_address == NULL) if (ifp->ip_address == NULL)
@ -256,6 +282,30 @@ void rtems_initialize_interfaces(void)
ifp->ip_netmask ifp->ip_netmask
); );
} }
#endif /*
* Set default route
*/
if (rtems_bsdnet_config.gateway && any_if_configured) {
struct sockaddr_in address;
struct sockaddr_in netmask;
struct sockaddr_in gateway;
rtems_bsdnet_initialize_sockaddr_in(&address);
rtems_bsdnet_initialize_sockaddr_in(&netmask);
rtems_bsdnet_initialize_sockaddr_in(&gateway);
gateway.sin_addr.s_addr = inet_addr (rtems_bsdnet_config.gateway);
if (rtems_bsdnet_rtrequest (
RTM_ADD,
(struct sockaddr *)&address,
(struct sockaddr *)&gateway,
(struct sockaddr *)&netmask,
(RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL) < 0) {
printf ("Can't set default route: %s\n", strerror (errno));
return -1;
}
}
return 0;
} }

View File

@ -88,7 +88,7 @@
/* Networking */ /* Networking */
#define IPSEC 1 #define IPSEC 1
#define INET 1 #define INET 1
#define INET6 1 // #define INET6 1
#define TCP_SIGNATURE 1 #define TCP_SIGNATURE 1
/* Integer type definitions */ /* Integer type definitions */