Changeset 695b6ff in mainline


Ignore:
Timestamp:
2013-09-12T21:26:18Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b8b1adb1, ddd0499d
Parents:
4a90582
Message:

Crude DHCP client prototype.

Files:
3 added
25 edited

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r4a90582 r695b6ff  
    267267uspace/dist/srv/rfb
    268268uspace/srv/hid/rfb/rfb
     269uspace/dist/srv/dhcp
     270uspace/srv/net/dhcp/dhcp
  • boot/Makefile.common

    r4a90582 r695b6ff  
    113113        $(USPACE_PATH)/srv/hid/isdv4_tablet/isdv4_tablet \
    114114        $(USPACE_PATH)/srv/hid/rfb/rfb \
     115        $(USPACE_PATH)/srv/net/dhcp/dhcp \
    115116        $(USPACE_PATH)/srv/net/dnsrsrv/dnsrsrv \
    116117        $(USPACE_PATH)/srv/net/ethip/ethip \
  • uspace/Makefile

    r4a90582 r695b6ff  
    9090        srv/devman \
    9191        srv/loader \
     92        srv/net/dhcp \
    9293        srv/net/dnsrsrv \
    9394        srv/net/ethip \
  • uspace/lib/c/generic/inet.c

    r4a90582 r695b6ff  
    111111       
    112112        ipc_call_t answer;
    113         aid_t req = async_send_3(exch, INET_SEND, dgram->tos, ttl, df,
    114             &answer);
     113        aid_t req = async_send_4(exch, INET_SEND, dgram->iplink, dgram->tos,
     114            ttl, df, &answer);
    115115       
    116116        int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t));
  • uspace/lib/c/generic/inet/addr.c

    r4a90582 r695b6ff  
    4747        #error The architecture must be either big-endian or little-endian.
    4848#endif
     49
     50const addr32_t addr32_broadcast_all_hosts = 0xffffffff;
    4951
    5052const addr48_t addr48_broadcast = {
  • uspace/lib/c/include/inet/addr.h

    r4a90582 r695b6ff  
    6868} inet_naddr_t;
    6969
     70extern const addr32_t addr32_broadcast_all_hosts;
    7071extern const addr48_t addr48_broadcast;
    7172
  • uspace/lib/c/include/inet/inet.h

    r4a90582 r695b6ff  
    3737
    3838#include <inet/addr.h>
     39#include <ipc/loc.h>
    3940#include <sys/types.h>
    4041
     
    4243
    4344typedef struct {
     45        /** Local IP link service ID (optional) */
     46        service_id_t iplink;
    4447        inet_addr_t src;
    4548        inet_addr_t dest;
  • uspace/lib/c/include/ipc/socket.h

    r4a90582 r695b6ff  
    198198#define SOCKET_GET_OPT_NAME(call) \
    199199        ({ \
    200                 int opt_name = (int) IPC_GET_ARG4(call); \
     200                int opt_name = (int) IPC_GET_ARG2(call); \
    201201                opt_name; \
    202202        })
  • uspace/lib/c/include/net/socket_codes.h

    r4a90582 r695b6ff  
    7575typedef int32_t socklen_t;
    7676
     77/* Socket options */
     78
     79enum {
     80        SOL_SOCKET = 1,
     81
     82        /* IP link to transmit on */
     83        SO_IPLINK
     84};
     85
    7786#endif
    7887
  • uspace/srv/net/dnsrsrv/dnsrsrv.c

    r4a90582 r695b6ff  
    6060        rc = transport_init();
    6161        if (rc != EOK) {
    62                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing tarnsport.");
     62                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing transport.");
    6363                return EIO;
    6464        }
  • uspace/srv/net/ethip/arp.c

    r4a90582 r695b6ff  
    9898    addr48_t mac_addr)
    9999{
     100        /* Broadcast address */
     101        if (ip_addr == addr32_broadcast_all_hosts) {
     102                addr48(addr48_broadcast, mac_addr);
     103                return EOK;
     104        }
     105
    100106        int rc = atrans_lookup(ip_addr, mac_addr);
    101107        if (rc == EOK)
  • uspace/srv/net/ethip/ethip_nic.c

    r4a90582 r695b6ff  
    202202        }
    203203
     204        rc = nic_broadcast_set_mode(nic->sess, NIC_BROADCAST_ACCEPTED);
     205        if (rc != EOK) {
     206                log_msg(LOG_DEFAULT, LVL_ERROR, "Error enabling "
     207                    "reception of broadcast frames on '%s'.", nic->svc_name);
     208                goto error;
     209        }
     210
    204211        log_msg(LOG_DEFAULT, LVL_DEBUG, "Initialized IP link service,");
    205212
  • uspace/srv/net/inetsrv/icmp.c

    r4a90582 r695b6ff  
    105105        reply->checksum = host2uint16_t_be(checksum);
    106106
     107        rdgram.iplink = 0;
    107108        rdgram.src = dgram->dest;
    108109        rdgram.dest = dgram->src;
     
    171172        inet_addr_set(sdu->dest, &dgram.dest);
    172173       
     174        dgram.iplink = 0;
    173175        dgram.tos = ICMP_TOS;
    174176        dgram.data = rdata;
  • uspace/srv/net/inetsrv/inet_link.c

    r4a90582 r695b6ff  
    235235        inet_addrobj_t *addr = NULL;
    236236       
     237        /* XXX FIXME Cannot rely on loopback being the first IP link service!! */
    237238        if (first_link) {
    238239                addr = inet_addrobj_new();
     
    240241                inet_naddr(&addr->naddr, 127, 0, 0, 1, 24);
    241242                first_link = false;
    242         } else {
    243                 /*
    244                  * FIXME
    245                  * Setting static IPv4 address for testing purposes:
    246                  * 10.0.2.15/24
    247                  */
    248                 addr = inet_addrobj_new();
    249                
    250                 inet_naddr(&addr->naddr, 10, 0, 2, 15, 24);
    251243        }
    252244       
  • uspace/srv/net/inetsrv/inetsrv.c

    r4a90582 r695b6ff  
    6868};
    6969
     70static inet_addr_t broadcast4_all_hosts = {
     71        .family = AF_INET,
     72        .addr = 0xffffffff
     73};
     74
    7075static inet_addr_t multicast_all_nodes = {
    7176        .family = AF_INET6,
     
    119124        }
    120125       
    121         inet_sroute_t *sroute = inet_sroute_new();
    122         if (sroute == NULL) {
    123                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed creating default route (%d).", rc);
    124                 return ENOMEM;
    125         }
    126 
    127         inet_naddr(&sroute->dest, 0, 0, 0, 0, 0);
    128         inet_addr(&sroute->router, 10, 0, 2, 2);
    129         sroute->name = str_dup("default");
    130         inet_sroute_add(sroute);
    131 
    132126        rc = inet_link_discovery_start();
    133127        if (rc != EOK)
     
    186180{
    187181        inet_dir_t dir;
     182        inet_link_t *ilink;
    188183        int rc;
     184
     185        if (dgram->iplink != 0) {
     186                log_msg(LOG_DEFAULT, LVL_DEBUG, "dgram directly to iplink %zu",
     187                    dgram->iplink);
     188                /* Send packet directly to the specified IP link */
     189                ilink = inet_link_get_by_id(dgram->iplink);
     190                if (ilink == 0)
     191                        return ENOENT;
     192
     193                if (dgram->src.family != AF_INET ||
     194                        dgram->dest.family != AF_INET)
     195                        return EINVAL;
     196
     197                return inet_link_send_dgram(ilink, dgram->src.addr,
     198                    dgram->dest.addr, dgram, proto, ttl, df);
     199        }
     200
     201        log_msg(LOG_DEFAULT, LVL_DEBUG, "dgram to be routed");
     202
     203        /* Route packet using source/destination addresses */
    189204
    190205        rc = inet_find_dir(&dgram->src, &dgram->dest, dgram->tos, &dir);
     
    214229
    215230        /* Take source address from the address object */
     231        if (remote->family == AF_INET && remote->addr == 0xffffffff) {
     232                local->family = AF_INET;
     233                local->addr = 0;
     234                return EOK;
     235        }
    216236        inet_naddr_addr(&dir.aobj->naddr, local);
    217237        return EOK;
     
    282302        inet_dgram_t dgram;
    283303       
    284         dgram.tos = IPC_GET_ARG1(*icall);
    285        
    286         uint8_t ttl = IPC_GET_ARG2(*icall);
     304        dgram.iplink = IPC_GET_ARG1(*icall);
     305        dgram.tos = IPC_GET_ARG2(*icall);
     306       
     307        uint8_t ttl = IPC_GET_ARG3(*icall);
    287308        int df = IPC_GET_ARG3(*icall);
    288309       
     
    524545        if ((addr != NULL) ||
    525546            (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) ||
    526             (inet_addr_compare(&multicast_all_nodes, &packet->dest))) {
     547            (inet_addr_compare(&multicast_all_nodes, &packet->dest)) ||
     548            (inet_addr_compare(&broadcast4_all_hosts, &packet->dest))) {
    527549                /* Destined for one of the local addresses */
    528550
  • uspace/srv/net/inetsrv/inetsrv.h

    r4a90582 r695b6ff  
    127127
    128128typedef struct {
     129        service_id_t iplink;
    129130        inet_addr_t src;
    130131        inet_addr_t dest;
  • uspace/srv/net/tcp/tcp.c

    r4a90582 r695b6ff  
    141141            pdu->text_size);
    142142
     143        dgram.iplink = 0;
    143144        dgram.src = pdu->src;
    144145        dgram.dest = pdu->dest;
  • uspace/srv/net/udp/assoc.c

    r4a90582 r695b6ff  
    184184        fibril_mutex_unlock(&assoc_list_lock);
    185185        udp_assoc_delref(assoc);
     186}
     187
     188/** Set IP link in association.
     189 *
     190 * @param assoc         Association
     191 * @param iplink        IP link
     192 */
     193void udp_assoc_set_iplink(udp_assoc_t *assoc, service_id_t iplink)
     194{
     195        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_iplink(%p, %zu)",
     196            assoc, iplink);
     197        fibril_mutex_lock(&assoc->lock);
     198        assoc->ident.iplink = iplink;
     199        fibril_mutex_unlock(&assoc->lock);
    186200}
    187201
  • uspace/srv/net/udp/assoc.h

    r4a90582 r695b6ff  
    3636#define ASSOC_H
    3737
     38#include <ipc/loc.h>
    3839#include <sys/types.h>
    3940#include "udp_type.h"
     
    4546extern void udp_assoc_addref(udp_assoc_t *);
    4647extern void udp_assoc_delref(udp_assoc_t *);
     48extern void udp_assoc_set_iplink(udp_assoc_t *, service_id_t);
    4749extern void udp_assoc_set_foreign(udp_assoc_t *, udp_sock_t *);
    4850extern void udp_assoc_set_local(udp_assoc_t *, udp_sock_t *);
  • uspace/srv/net/udp/pdu.c

    r4a90582 r695b6ff  
    215215                return ENOMEM;
    216216
     217        npdu->iplink = sp->iplink;
    217218        npdu->src = sp->local.addr;
    218219        npdu->dest = sp->foreign.addr;
  • uspace/srv/net/udp/sock.c

    r4a90582 r695b6ff  
    11/*
    22 * Copyright (c) 2008 Lukas Mejdrech
    3  * Copyright (c) 2012 Jiri Svoboda
     3 * Copyright (c) 2013 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    349349        fibril_mutex_lock(&socket->lock);
    350350       
    351         if (inet_addr_is_any(&socket->assoc->ident.local.addr)) {
     351        if (inet_addr_is_any(&socket->assoc->ident.local.addr) &&
     352                socket->assoc->ident.iplink == 0) {
    352353                /* Determine local IP address */
    353354                inet_addr_t loc_addr;
     
    665666static void udp_sock_setsockopt(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
    666667{
    667         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_setsockopt()");
    668         async_answer_0(callid, ENOTSUP);
    669 }
     668        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_setsockopt)");
     669        log_msg(LOG_DEFAULT, LVL_DEBUG, " - async_data_write_accept");
     670       
     671        void *data = NULL;
     672        size_t data_len;
     673        int rc = async_data_write_accept(&data, false, 0, 0, 0, &data_len);
     674        if (rc != EOK) {
     675                log_msg(LOG_DEFAULT, LVL_DEBUG, " - failed accepting data");
     676                async_answer_0(callid, rc);
     677                return;
     678        }
     679       
     680        sysarg_t opt_level = SOL_SOCKET;
     681        sysarg_t opt_name = SOCKET_GET_OPT_NAME(call);
     682       
     683        if (opt_level != SOL_SOCKET || opt_name != SO_IPLINK ||
     684            data_len != sizeof(service_id_t)) {
     685                log_msg(LOG_DEFAULT, LVL_DEBUG, " - failed opt_level/name/len");
     686                log_msg(LOG_DEFAULT, LVL_DEBUG, " - failed opt_level=%d, "
     687                    "opt_name=%d, data_len=%zu", (int)opt_level, (int)opt_name,
     688                    data_len);
     689                async_answer_0(callid, EINVAL);
     690                return;
     691        }
     692       
     693        log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_cores_find");
     694       
     695        socket_core_t *sock_core = socket_cores_find(&client->sockets,
     696            SOCKET_GET_SOCKET_ID(call));
     697        if (sock_core == NULL) {
     698                log_msg(LOG_DEFAULT, LVL_DEBUG, " - failed getting sock_core");
     699                async_answer_0(callid, ENOENT);
     700                return;
     701        }
     702       
     703        udp_sockdata_t *socket =
     704            (udp_sockdata_t *) sock_core->specific_data;
     705       
     706        service_id_t iplink = *(service_id_t *)data;
     707        udp_uc_set_iplink(socket->assoc, iplink);
     708       
     709        log_msg(LOG_DEFAULT, LVL_DEBUG, " - success");
     710        async_answer_0(callid, EOK);
     711}
     712
    670713
    671714static int udp_sock_recv_fibril(void *arg)
     
    714757
    715758        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recv_fibril() exited loop");
    716         fibril_mutex_unlock(&sock->recv_buffer_lock);
    717759        udp_uc_destroy(sock->assoc);
    718760
     
    730772        /* Accept the connection */
    731773        async_answer_0(iid, EOK);
     774
     775        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_connection: begin");
    732776
    733777        client.sess = async_callback_receive(EXCHANGE_SERIALIZE);
  • uspace/srv/net/udp/ucall.c

    r4a90582 r695b6ff  
    5555        *assoc = nassoc;
    5656        return UDP_EOK;
     57}
     58
     59void udp_uc_set_iplink(udp_assoc_t *assoc, service_id_t iplink)
     60{
     61        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_iplink(%p, %zu)",
     62            assoc, iplink);
     63
     64        udp_assoc_set_iplink(assoc, iplink);
    5765}
    5866
  • uspace/srv/net/udp/ucall.h

    r4a90582 r695b6ff  
    3636#define UCALL_H
    3737
     38#include <ipc/loc.h>
    3839#include <sys/types.h>
    3940#include "udp_type.h"
    4041
    4142extern udp_error_t udp_uc_create(udp_assoc_t **);
     43extern void udp_uc_set_iplink(udp_assoc_t *, service_id_t);
    4244extern udp_error_t udp_uc_set_foreign(udp_assoc_t *, udp_sock_t *);
    4345extern udp_error_t udp_uc_set_local(udp_assoc_t *, udp_sock_t *);
  • uspace/srv/net/udp/udp_inet.c

    r4a90582 r695b6ff  
    8484        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_transmit_pdu()");
    8585
     86        dgram.iplink = pdu->iplink;
    8687        dgram.src = pdu->src;
    8788        dgram.dest = pdu->dest;
  • uspace/srv/net/udp/udp_type.h

    r4a90582 r695b6ff  
    3838#include <fibril.h>
    3939#include <fibril_synch.h>
     40#include <ipc/loc.h>
    4041#include <socket_core.h>
    4142#include <sys/types.h>
     
    7172
    7273typedef struct {
     74        service_id_t iplink;
    7375        udp_sock_t local;
    7476        udp_sock_t foreign;
     
    8587/** Encoded PDU */
    8688typedef struct {
     89        /** IP link (optional) */
     90        service_id_t iplink;
    8791        /** Source address */
    8892        inet_addr_t src;
    8993        /** Destination address */
    9094        inet_addr_t dest;
    91        
    9295        /** Encoded PDU data including header */
    9396        void *data;
     
    143146        /** Connection */
    144147        udp_assoc_t *assoc;
     148        /** User-configured IP link */
     149        service_id_t iplink;
    145150        /** Receiving fibril */
    146151        fid_t recv_fibril;
Note: See TracChangeset for help on using the changeset viewer.