Changeset bd6dd6e in rtems-libbsd


Ignore:
Timestamp:
Jul 27, 2012, 12:45:06 PM (7 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, fd86c091b97759106da7355ce1dd81ebe030e285, freebsd-9.3, f020f08430150c1656a0ad0a1de13699db9b980b
Children:
71703fe
Parents:
4a3e489
Message:

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".

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • freebsd-userspace/Makefile

    r4a3e489 rbd6dd6e  
    88#CFLAGS += -ffreestanding
    99CFLAGS += -I include
     10CFLAGS += -I rtems/include
    1011CFLAGS += -I lib/libc/include
    1112CFLAGS += -I sys
     
    109110        cd include; for i in `find . -name '*.h'` ; do \
    110111          install -c -m 644 -D "$$i" "$(INSTALL_BASE)/include/$$i" ; done
     112        cd rtems/include; for i in `find . -name '*.h'` ; do \
     113          install -c -m 644 -D "$$i" "$(INSTALL_BASE)/include/$$i" ; done
    111114        install -c -m 644 $(LIB) $(INSTALL_BASE)
    112115
  • freebsd-userspace/rtems/rtems-net-setup.c

    r4a3e489 rbd6dd6e  
    1010#include <netinet/in.h>
    1111#include <arpa/inet.h>
     12#include <net/route.h>
     13#include <rtems/rtems_bsdnet.h>
    1214
    1315static const struct sockaddr_in address_template = {
     
    1921};
    2022
     23/*
     24 * Manipulate routing tables
     25 */
     26int rtems_bsdnet_rtrequest(
     27  int              req,
     28  struct sockaddr *dst,
     29  struct sockaddr *gateway,
     30  struct sockaddr *netmask,
     31  int              flags,
     32  struct rtentry **net_nrt
     33)
     34{
     35  int error;
     36
     37  // rtems_bsdnet_semaphore_obtain();
     38  error = rtrequest(req, dst, gateway, netmask, flags, net_nrt);
     39  // rtems_bsdnet_semaphore_release();
     40  if (error) {
     41    errno = error;
     42    return -1;
     43  }
     44  return 0;
     45}
     46
    2147static void
    2248rtems_bsdnet_initialize_sockaddr_in(struct sockaddr_in *addr)
     
    3662   * Configure interfaces
    3763   */
    38   s = socket (AF_INET, SOCK_DGRAM, 0);
     64  s = socket(AF_INET, SOCK_DGRAM, 0);
    3965  if (s < 0)
    4066    return -1;
    4167
    42   strncpy (ifreq.ifr_name, ifname, IFNAMSIZ);
     68  strncpy(ifreq.ifr_name, ifname, IFNAMSIZ);
    4369
    4470  switch (cmd) {
    4571    case SIOCSIFADDR:
    4672    case SIOCSIFNETMASK:
    47       memcpy (&ifreq.ifr_addr, param, sizeof (struct sockaddr));
    48       r = ioctl (s, cmd, &ifreq);
     73      memcpy(&ifreq.ifr_addr, param, sizeof(struct sockaddr));
     74      r = ioctl(s, cmd, &ifreq);
    4975      break;
    5076
     
    5379    case OSIOCGIFNETMASK:
    5480    case SIOCGIFNETMASK:
    55       if ((r = ioctl (s, cmd, &ifreq)) < 0)
    56         break;
    57       memcpy (param, &ifreq.ifr_addr, sizeof (struct sockaddr));
     81      if ((r = ioctl(s, cmd, &ifreq)) < 0)
     82        break;
     83      memcpy(param, &ifreq.ifr_addr, sizeof(struct sockaddr));
    5884      break;
    5985
    6086    case SIOCGIFFLAGS:
    6187    case SIOCSIFFLAGS:
    62       if ((r = ioctl (s, SIOCGIFFLAGS, &ifreq)) < 0)
     88      if ((r = ioctl(s, SIOCGIFFLAGS, &ifreq)) < 0)
    6389        break;
    6490      if (cmd == SIOCGIFFLAGS) {
     
    7197          ifreq.ifr_flags &= ~(IFF_UP);
    7298      }
    73       r = ioctl (s, SIOCSIFFLAGS, &ifreq);
     99      r = ioctl(s, SIOCSIFFLAGS, &ifreq);
    74100      break;
    75101
    76102    case SIOCSIFDSTADDR:
    77       memcpy (&ifreq.ifr_dstaddr, param, sizeof (struct sockaddr));
    78       r = ioctl (s, cmd, &ifreq);
     103      memcpy(&ifreq.ifr_dstaddr, param, sizeof(struct sockaddr));
     104      r = ioctl(s, cmd, &ifreq);
    79105      break;
    80106
    81107    case OSIOCGIFDSTADDR:
    82108    case SIOCGIFDSTADDR:
    83       if ((r = ioctl (s, cmd, &ifreq)) < 0)
    84         break;
    85       memcpy (param, &ifreq.ifr_dstaddr, sizeof (struct sockaddr));
     109      if ((r = ioctl(s, cmd, &ifreq)) < 0)
     110        break;
     111      memcpy(param, &ifreq.ifr_dstaddr, sizeof(struct sockaddr));
    86112      break;
    87113
    88114    case SIOCSIFBRDADDR:
    89       memcpy (&ifreq.ifr_broadaddr, param, sizeof (struct sockaddr));
    90       r = ioctl (s, cmd, &ifreq);
     115      memcpy(&ifreq.ifr_broadaddr, param, sizeof(struct sockaddr));
     116      r = ioctl(s, cmd, &ifreq);
    91117      break;
    92118
    93119    case OSIOCGIFBRDADDR:
    94120    case SIOCGIFBRDADDR:
    95       if ((r = ioctl (s, cmd, &ifreq)) < 0)
    96         break;
    97       memcpy (param, &ifreq.ifr_broadaddr, sizeof (struct sockaddr));
     121      if ((r = ioctl(s, cmd, &ifreq)) < 0)
     122        break;
     123      memcpy(param, &ifreq.ifr_broadaddr, sizeof(struct sockaddr));
    98124      break;
    99125
    100126    case SIOCSIFMETRIC:
    101127      ifreq.ifr_metric = *((int*) param);
    102       r = ioctl (s, cmd, &ifreq);
     128      r = ioctl(s, cmd, &ifreq);
    103129      break;
    104130
    105131    case SIOCGIFMETRIC:
    106       if ((r = ioctl (s, cmd, &ifreq)) < 0)
     132      if ((r = ioctl(s, cmd, &ifreq)) < 0)
    107133        break;
    108134      *((int*) param) = ifreq.ifr_metric;
     
    111137    case SIOCSIFMTU:
    112138      ifreq.ifr_mtu = *((int*) param);
    113       r = ioctl (s, cmd, &ifreq);
     139      r = ioctl(s, cmd, &ifreq);
    114140      break;
    115141
    116142    case SIOCGIFMTU:
    117       if ((r = ioctl (s, cmd, &ifreq)) < 0)
     143      if ((r = ioctl(s, cmd, &ifreq)) < 0)
    118144        break;
    119145      *((int*) param) = ifreq.ifr_mtu;
     
    122148    case SIOCSIFPHYS:
    123149      ifreq.ifr_phys = *((int*) param);
    124       r = ioctl (s, cmd, &ifreq);
     150      r = ioctl(s, cmd, &ifreq);
    125151      break;
    126152
    127153    case SIOCGIFPHYS:
    128       if ((r = ioctl (s, cmd, &ifreq)) < 0)
     154      if ((r = ioctl(s, cmd, &ifreq)) < 0)
    129155        break;
    130156      *((int*) param) = ifreq.ifr_phys;
     
    133159    case SIOCSIFMEDIA:
    134160      ifreq.ifr_media = *((int*) param);
    135       r = ioctl (s, cmd, &ifreq);
     161      r = ioctl(s, cmd, &ifreq);
    136162      break;
    137163
     
    141167       */
    142168      ifreq.ifr_media = *((int*) param);
    143       if ((r = ioctl (s, cmd, &ifreq)) < 0)
     169      if ((r = ioctl(s, cmd, &ifreq)) < 0)
    144170        break;
    145171      *((int*) param) = ifreq.ifr_media;
     
    157183  }
    158184
    159   close (s);
     185  close(s);
    160186  return r;
    161187}
     
    177203   */
    178204  flags = IFF_UP;
    179   if (rtems_bsdnet_ifconfig (name, SIOCSIFFLAGS, &flags) < 0) {
    180     printf ("Can't bring %s up: %s\n", name, strerror (errno));
     205  if (rtems_bsdnet_ifconfig(name, SIOCSIFFLAGS, &flags) < 0) {
     206    printf("Can't bring %s up: %s\n", name, strerror(errno));
    181207    return false;
    182208  }
     
    186212   */
    187213  rtems_bsdnet_initialize_sockaddr_in(&netmask);
    188   netmask.sin_addr.s_addr = inet_addr (ip_netmask);
    189   if (rtems_bsdnet_ifconfig (name, SIOCSIFNETMASK, &netmask) < 0) {
    190     printf ("Can't set %s netmask: %s\n", name, strerror (errno));
     214  netmask.sin_addr.s_addr = inet_addr(ip_netmask);
     215  if (rtems_bsdnet_ifconfig(name, SIOCSIFNETMASK, &netmask) < 0) {
     216    printf("Can't set %s netmask: %s\n", name, strerror(errno));
    191217    return false;
    192218  }
     
    196222   */
    197223  rtems_bsdnet_initialize_sockaddr_in(&address);
    198   address.sin_addr.s_addr = inet_addr (ip_address);
    199   if (rtems_bsdnet_ifconfig (name, SIOCSIFADDR, &address) < 0) {
    200     printf ("Can't set %s address: %s\n", name, strerror (errno));
     224  address.sin_addr.s_addr = inet_addr(ip_address);
     225  if (rtems_bsdnet_ifconfig(name, SIOCSIFADDR, &address) < 0) {
     226    printf("Can't set %s address: %s\n", name, strerror(errno));
    201227    return false;
    202228  }
     
    206232   * broadcast flag set.
    207233   */
    208   if (rtems_bsdnet_ifconfig (name, SIOCGIFFLAGS, &flags) < 0) {
    209     printf ("Can't read %s flags: %s\n", name, strerror (errno));
     234  if (rtems_bsdnet_ifconfig(name, SIOCGIFFLAGS, &flags) < 0) {
     235    printf("Can't read %s flags: %s\n", name, strerror(errno));
    210236    return false;
    211237  }
     
    217243    broadcast.sin_addr.s_addr =
    218244        address.sin_addr.s_addr | ~netmask.sin_addr.s_addr;
    219     if (rtems_bsdnet_ifconfig (name, SIOCSIFBRDADDR, &broadcast) < 0) {
     245    if (rtems_bsdnet_ifconfig(name, SIOCSIFBRDADDR, &broadcast) < 0) {
    220246      struct in_addr  in_addr;
    221247      char      buf[20];
     
    223249      if (!inet_ntop(AF_INET, &in_addr, buf, sizeof(buf)))
    224250          strcpy(buf,"?.?.?.?");
    225       printf ("Can't set %s broadcast address %s: %s\n",
    226         name, buf, strerror (errno));
     251      printf("Can't set %s broadcast address %s: %s\n",
     252        name, buf, strerror(errno));
    227253    }
    228254  }
     
    235261void rtems_initialize_interfaces(void)
    236262{
    237   bool any_if_configured;
     263  bool                          any_if_configured;
     264  struct rtems_bsdnet_ifconfig *ifp;
    238265
    239266  any_if_configured = false;
     
    245272  );
    246273
    247 #if 0
    248274
    249275  for (ifp = rtems_bsdnet_config.ifconfig ; ifp ; ifp = ifp->next) {
     
    257283    );
    258284  }
    259 #endif
    260 
    261 }
     285  /*
     286   * Set default route
     287   */
     288  if (rtems_bsdnet_config.gateway && any_if_configured) {
     289    struct sockaddr_in address;
     290    struct sockaddr_in netmask;
     291    struct sockaddr_in gateway;
     292
     293    rtems_bsdnet_initialize_sockaddr_in(&address);
     294    rtems_bsdnet_initialize_sockaddr_in(&netmask);
     295    rtems_bsdnet_initialize_sockaddr_in(&gateway);
     296
     297    gateway.sin_addr.s_addr = inet_addr (rtems_bsdnet_config.gateway);
     298
     299    if (rtems_bsdnet_rtrequest (
     300        RTM_ADD,
     301        (struct sockaddr *)&address,
     302        (struct sockaddr *)&gateway,
     303        (struct sockaddr *)&netmask,
     304        (RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL) < 0) {
     305      printf ("Can't set default route: %s\n", strerror (errno));
     306      return -1;
     307    }
     308  }
     309  return 0;
     310
     311}
  • rtemsbsd/freebsd/machine/rtems-bsd-config.h

    r4a3e489 rbd6dd6e  
    8989#define IPSEC 1
    9090#define INET  1
    91 #define INET6 1
     91// #define INET6 1
    9292#define TCP_SIGNATURE 1
    9393
Note: See TracChangeset for help on using the changeset viewer.