From 4bde23948cac7627031c6a12ac9aeb6ce6746e42 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 19 Sep 2001 17:30:38 +0000 Subject: 2001-09-19 Chris Johns * nfs/bootp_subr.c, rtems/rtems_bootp.c, rtems/rtems_bsdnet.h, rtems/rtems_bsdnet_internal.h Added support for populating the initial "root" filesystem with information obtained via the DHCP response. --- cpukit/libnetworking/ChangeLog | 7 ++ cpukit/libnetworking/nfs/bootp_subr.c | 84 +++++++++++++++++++++- cpukit/libnetworking/rtems/rtems_bootp.c | 14 +++- cpukit/libnetworking/rtems/rtems_bsdnet.h | 2 + cpukit/libnetworking/rtems/rtems_bsdnet_internal.h | 2 +- 5 files changed, 104 insertions(+), 5 deletions(-) (limited to 'cpukit') diff --git a/cpukit/libnetworking/ChangeLog b/cpukit/libnetworking/ChangeLog index fd5db5cf00..fa79ed7f87 100644 --- a/cpukit/libnetworking/ChangeLog +++ b/cpukit/libnetworking/ChangeLog @@ -1,3 +1,10 @@ +2001-09-19 Chris Johns + + * nfs/bootp_subr.c, rtems/rtems_bootp.c, rtems/rtems_bsdnet.h, + rtems/rtems_bsdnet_internal.h Added support for populating the + initial "root" filesystem with information obtained via the DHCP + response. + 2001-08-16 Mike Siers * pppd/STATUS: Updated by Joel based upon email from Mike. diff --git a/cpukit/libnetworking/nfs/bootp_subr.c b/cpukit/libnetworking/nfs/bootp_subr.c index b809143d6d..1df2d084cd 100644 --- a/cpukit/libnetworking/nfs/bootp_subr.c +++ b/cpukit/libnetworking/nfs/bootp_subr.c @@ -69,6 +69,11 @@ #include #include +#include +#include +#include +#include + #define BOOTP_MIN_LEN 300 /* Minimum size of bootp udp packet */ /* @@ -147,7 +152,7 @@ bootpc_adjust_interface(struct ifreq *ireq,struct socket *so, struct sockaddr_in *gw, struct proc *procp); -void bootpc_init(void); +void bootpc_init(int update_files); #ifdef BOOTP_DEBUG void bootpboot_p_sa(sa,ma) @@ -689,6 +694,7 @@ static char dhcp_gotserver = 0; static char dhcp_gotlogserver = 0; static struct sockaddr_in dhcp_netmask; static struct sockaddr_in dhcp_gw; +static char *dhcp_hostname; static void processOptions (unsigned char *optbuf, int optbufSize) @@ -795,6 +801,7 @@ processOptions (unsigned char *optbuf, int optbufSize) if (sethostname (p, len) < 0) panic("Can't set host name"); printf("Hostname is %s\n", p); + dhcp_hostname = strdup(p); break; case 7: @@ -864,7 +871,7 @@ processOptions (unsigned char *optbuf, int optbufSize) #define EALEN 6 void -bootpc_init(void) +bootpc_init(int update_files) { struct bootp_packet call; struct bootp_packet reply; @@ -887,6 +894,18 @@ bootpc_init(void) if (nfs_diskless_valid) return; + /* + * If we are to update the files create the root + * file structure. + */ + if (update_files) + if (rtems_create_root_fs () < 0) { + printf("Error creating the root filesystem.\nFile not created.\n"); + update_files = 0; + } + + memset(dhcp_hostname, 0, sizeof(dhcp_hostname)); + /* * Find a network interface. */ @@ -1026,7 +1045,66 @@ bootpc_init(void) if (!dhcp_gotlogserver) rtems_bsdnet_log_host_address = rtems_bsdnet_bootp_server_address; printip ("Log server ip address", rtems_bsdnet_log_host_address); - + + /* + * Update the files if we are asked too. + */ + if (update_files) { + char *dn = rtems_bsdnet_domain_name; + char *hn = dhcp_hostname; + if (!dn) + dn = "mydomain"; + if (!hn) + hn = "me"; + rtems_rootfs_append_host_rec(*((unsigned long*) &myaddr.sin_addr), hn, dn); + + /* + * Should the given domainname be used here ? + */ + if (dhcp_gotserver) { + if (rtems_bsdnet_bootp_server_name) + hn = rtems_bsdnet_bootp_server_name; + else + hn = "bootps"; + rtems_rootfs_append_host_rec(*((unsigned long *) &rtems_bsdnet_bootp_server_address), + hn, dn); + } + + if (dhcp_gotlogserver) { + rtems_rootfs_append_host_rec(*((unsigned long *) &rtems_bsdnet_log_host_address), + "logs", dn); + } + + /* + * Setup the DNS configuration file /etc/resolv.conf. + */ + if (rtems_bsdnet_nameserver_count) { + int i; + char buf[64]; + const char *bufl[1]; + + bufl[0] = buf; + +#define MKFILE_MODE (S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH) + + if (rtems_bsdnet_domain_name && + (strlen(rtems_bsdnet_domain_name) < (sizeof(buf) - 1))) { + strcpy(buf, "search "); + strcat(buf, rtems_bsdnet_domain_name); + strcat(buf, "\n"); + rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl); + } + + for (i = 0; i < rtems_bsdnet_nameserver_count; i++) { + strcpy(buf, "nameserver "); + strcat(buf, inet_ntoa(rtems_bsdnet_ntpserver[i])); + strcat(buf, "\n"); + if (rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl)) + break; + } + } + } + /* * Configure the interface with the new settings */ diff --git a/cpukit/libnetworking/rtems/rtems_bootp.c b/cpukit/libnetworking/rtems/rtems_bootp.c index 47e3db758f..76bb79170e 100644 --- a/cpukit/libnetworking/rtems/rtems_bootp.c +++ b/cpukit/libnetworking/rtems/rtems_bootp.c @@ -14,6 +14,18 @@ void rtems_bsdnet_do_bootp (void) { rtems_bsdnet_semaphore_obtain (); - bootpc_init (); + bootpc_init (FALSE); + rtems_bsdnet_semaphore_release (); +} + +/* + * Perform a BOOTP request and update "standard" files in /etc + * with the results. + */ +void +rtems_bsdnet_do_bootp_and_rootfs (void) +{ + rtems_bsdnet_semaphore_obtain (); + bootpc_init (TRUE); rtems_bsdnet_semaphore_release (); } diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet.h b/cpukit/libnetworking/rtems/rtems_bsdnet.h index 7838835f0f..6c60ce1abe 100644 --- a/cpukit/libnetworking/rtems/rtems_bsdnet.h +++ b/cpukit/libnetworking/rtems/rtems_bsdnet.h @@ -170,6 +170,8 @@ void rtems_bsdnet_detach (struct rtems_bsdnet_ifconfig *ifconfig); int rtems_bsdnet_ifconfig (const char *ifname, unsigned32 cmd, void *param); void rtems_bsdnet_do_bootp (void); +void rtems_bsdnet_do_bootp_and_rootfs (void); + int rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority); #endif /* _RTEMS_BSDNET_ */ diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h index f95f1a1640..4b8c4fa652 100644 --- a/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h +++ b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h @@ -175,7 +175,7 @@ void domaininit (void *); void ifinit (void *); void ipintr (void); void arpintr (void); -void bootpc_init(void); +void bootpc_init(int ); int socket (int, int, int); int ioctl (int, int, ...); -- cgit v1.2.3