Changeset 8bf672d in mainline for uspace/srv/inet/inet.c


Ignore:
Timestamp:
2012-03-30T17:42:11Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
66a272f8
Parents:
3b3c689
Message:

Static route configuration.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/inet/inet.c

    r3b3c689 r8bf672d  
    5454#include "inetping.h"
    5555#include "inet_link.h"
     56#include "sroute.h"
    5657
    5758#define NAME "inet"
     
    120121}
    121122
     123static int inet_find_dir(inet_addr_t *src, inet_addr_t *dest, uint8_t tos,
     124    inet_dir_t *dir)
     125{
     126        inet_sroute_t *sr;
     127
     128        /* XXX Handle case where source address is specified */
     129        (void) src;
     130
     131        dir->aobj = inet_addrobj_find(dest, iaf_net);
     132        if (dir->aobj != NULL) {
     133                dir->ldest = *dest;
     134                dir->dtype = dt_direct;
     135        } else {
     136                /* No direct path, try using a static route */
     137                sr = inet_sroute_find(dest);
     138                if (sr != NULL) {
     139                        dir->aobj = inet_addrobj_find(&sr->router, iaf_net);
     140                        dir->ldest = sr->router;
     141                        dir->dtype = dt_router;
     142                }
     143        }
     144
     145        if (dir->aobj == NULL) {
     146                log_msg(LVL_DEBUG, "inet_send: No route to destination.");
     147                return ENOENT;
     148        }
     149
     150        return EOK;
     151}
     152
    122153int inet_route_packet(inet_dgram_t *dgram, uint8_t proto, uint8_t ttl,
    123154    int df)
    124155{
    125         inet_addrobj_t *addr;
    126 
    127         addr = inet_addrobj_find(&dgram->dest, iaf_net);
    128         if (addr != NULL) {
    129                 /* Destination is directly accessible */
    130                 return inet_addrobj_send_dgram(addr, dgram, proto, ttl, df);
    131         }
    132 
    133         /* TODO: Gateways */
    134         log_msg(LVL_DEBUG, "inet_send: No route to destination.");
    135         return ENOENT;
     156        inet_dir_t dir;
     157        int rc;
     158
     159        rc = inet_find_dir(&dgram->src, &dgram->dest, dgram->tos, &dir);
     160        if (rc != EOK)
     161                return rc;
     162
     163        return inet_addrobj_send_dgram(dir.aobj, &dir.ldest, dgram,
     164            proto, ttl, df);
    136165}
    137166
     
    144173int inet_get_srcaddr(inet_addr_t *remote, uint8_t tos, inet_addr_t *local)
    145174{
    146         inet_addrobj_t *addr;
    147 
    148         addr = inet_addrobj_find(remote, iaf_net);
    149         if (addr != NULL) {
    150                 /* Destination is directly accessible */
    151                 local->ipv4 = addr->naddr.ipv4;
    152                 return EOK;
    153         }
    154 
    155         return ENOENT;
     175        inet_dir_t dir;
     176        int rc;
     177
     178        rc = inet_find_dir(NULL, remote, tos, &dir);
     179        if (rc != EOK)
     180                return rc;
     181
     182        /* XXX dt_local? */
     183
     184        /* Take source address from the address object */
     185        local->ipv4 = dir.aobj->naddr.ipv4;
     186        return EOK;
    156187}
    157188
Note: See TracChangeset for help on using the changeset viewer.