Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/loopip/loopip.c

    ra17356fd ra1a101d  
    3939#include <errno.h>
    4040#include <inet/iplink_srv.h>
    41 #include <inet/addr.h>
    42 #include <net/socket_codes.h>
    4341#include <io/log.h>
    4442#include <loc.h>
     
    4644#include <stdlib.h>
    4745
    48 #define NAME  "loopip"
     46#define NAME "loopip"
    4947
    5048static int loopip_open(iplink_srv_t *srv);
    5149static int loopip_close(iplink_srv_t *srv);
    52 static int loopip_send(iplink_srv_t *srv, iplink_sdu_t *sdu);
    53 static int loopip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu);
     50static int loopip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu);
    5451static int loopip_get_mtu(iplink_srv_t *srv, size_t *mtu);
    55 static int loopip_get_mac48(iplink_srv_t *srv, addr48_t *mac);
    56 static int loopip_addr_add(iplink_srv_t *srv, inet_addr_t *addr);
    57 static int loopip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr);
     52static int loopip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr);
     53static int loopip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr);
    5854
    5955static void loopip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     
    6359        .close = loopip_close,
    6460        .send = loopip_send,
    65         .send6 = loopip_send6,
    6661        .get_mtu = loopip_get_mtu,
    67         .get_mac48 = loopip_get_mac48,
    6862        .addr_add = loopip_addr_add,
    6963        .addr_remove = loopip_addr_remove
     
    7569typedef struct {
    7670        link_t link;
    77        
    78         uint16_t af;
    79         iplink_recv_sdu_t sdu;
     71        iplink_srv_sdu_t sdu;
    8072} rqueue_entry_t;
    8173
     
    8577                log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_recv_fibril(): Wait for one item");
    8678                link_t *link = prodcons_consume(&loopip_rcv_queue);
    87                 rqueue_entry_t *rqe =
    88                     list_get_instance(link, rqueue_entry_t, link);
    89                
    90                 (void) iplink_ev_recv(&loopip_iplink, &rqe->sdu, rqe->af);
    91                
    92                 free(rqe->sdu.data);
    93                 free(rqe);
    94         }
     79                rqueue_entry_t *rqe = list_get_instance(link, rqueue_entry_t, link);
     80
     81                (void) iplink_ev_recv(&loopip_iplink, &rqe->sdu);
     82        }
     83
     84        return 0;
     85}
     86
     87static int loopip_init(void)
     88{
     89        int rc;
     90        service_id_t sid;
     91        category_id_t iplink_cat;
     92        const char *svc_name = "net/loopback";
    9593       
    96         return 0;
    97 }
    98 
    99 static int loopip_init(void)
    100 {
    10194        async_set_client_connection(loopip_client_conn);
    10295       
    103         int rc = loc_server_register(NAME);
     96        rc = loc_server_register(NAME);
    10497        if (rc != EOK) {
    10598                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server.");
    10699                return rc;
    107100        }
    108        
     101
    109102        iplink_srv_init(&loopip_iplink);
    110103        loopip_iplink.ops = &loopip_iplink_ops;
    111104        loopip_iplink.arg = NULL;
    112        
     105
    113106        prodcons_initialize(&loopip_rcv_queue);
    114        
    115         const char *svc_name = "net/loopback";
    116         service_id_t sid;
     107
    117108        rc = loc_service_register(svc_name, &sid);
    118109        if (rc != EOK) {
    119                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service %s.",
    120                     svc_name);
    121                 return rc;
    122         }
    123        
    124         category_id_t iplink_cat;
     110                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service %s.", svc_name);
     111                return rc;
     112        }
     113
    125114        rc = loc_category_get_id("iplink", &iplink_cat, IPC_FLAG_BLOCKING);
    126115        if (rc != EOK) {
     
    128117                return rc;
    129118        }
    130        
     119
    131120        rc = loc_service_add_to_cat(sid, iplink_cat);
    132121        if (rc != EOK) {
    133                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding %s to category.",
    134                     svc_name);
    135                 return rc;
    136         }
    137        
     122                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding %s to category.", svc_name);
     123                return rc;
     124        }
     125
    138126        fid_t fid = fibril_create(loopip_recv_fibril, NULL);
    139127        if (fid == 0)
    140128                return ENOMEM;
    141        
     129
    142130        fibril_add_ready(fid);
    143        
     131
    144132        return EOK;
    145133}
     
    163151}
    164152
    165 static int loopip_send(iplink_srv_t *srv, iplink_sdu_t *sdu)
    166 {
     153static int loopip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu)
     154{
     155        rqueue_entry_t *rqe;
     156
    167157        log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_send()");
    168        
    169         rqueue_entry_t *rqe = calloc(1, sizeof(rqueue_entry_t));
     158
     159        rqe = calloc(1, sizeof(rqueue_entry_t));
    170160        if (rqe == NULL)
    171161                return ENOMEM;
    172        
    173162        /*
    174163         * Clone SDU
    175164         */
    176         rqe->af = AF_INET;
     165        rqe->sdu.lsrc = sdu->ldest;
     166        rqe->sdu.ldest = sdu->lsrc;
    177167        rqe->sdu.data = malloc(sdu->size);
    178168        if (rqe->sdu.data == NULL) {
     
    180170                return ENOMEM;
    181171        }
    182        
     172
    183173        memcpy(rqe->sdu.data, sdu->data, sdu->size);
    184174        rqe->sdu.size = sdu->size;
    185        
     175
    186176        /*
    187177         * Insert to receive queue
    188178         */
    189179        prodcons_produce(&loopip_rcv_queue, &rqe->link);
    190        
    191         return EOK;
    192 }
    193 
    194 static int loopip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu)
    195 {
    196         log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip6_send()");
    197        
    198         rqueue_entry_t *rqe = calloc(1, sizeof(rqueue_entry_t));
    199         if (rqe == NULL)
    200                 return ENOMEM;
    201        
    202         /*
    203          * Clone SDU
    204          */
    205         rqe->af = AF_INET6;
    206         rqe->sdu.data = malloc(sdu->size);
    207         if (rqe->sdu.data == NULL) {
    208                 free(rqe);
    209                 return ENOMEM;
    210         }
    211        
    212         memcpy(rqe->sdu.data, sdu->data, sdu->size);
    213         rqe->sdu.size = sdu->size;
    214        
    215         /*
    216          * Insert to receive queue
    217          */
    218         prodcons_produce(&loopip_rcv_queue, &rqe->link);
    219        
     180
    220181        return EOK;
    221182}
     
    228189}
    229190
    230 static int loopip_get_mac48(iplink_srv_t *src, addr48_t *mac)
    231 {
    232         log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_get_mac48()");
    233         return ENOTSUP;
    234 }
    235 
    236 static int loopip_addr_add(iplink_srv_t *srv, inet_addr_t *addr)
    237 {
    238         return EOK;
    239 }
    240 
    241 static int loopip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr)
    242 {
     191static int loopip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr)
     192{
     193        log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_addr_add(0x%" PRIx32 ")", addr->ipv4);
     194        return EOK;
     195}
     196
     197static int loopip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr)
     198{
     199        log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_addr_remove(0x%" PRIx32 ")", addr->ipv4);
    243200        return EOK;
    244201}
     
    246203int main(int argc, char *argv[])
    247204{
    248         printf("%s: HelenOS loopback IP link provider\n", NAME);
    249        
    250         int rc = log_init(NAME);
    251         if (rc != EOK) {
    252                 printf("%s: Failed to initialize logging.\n", NAME);
    253                 return rc;
    254         }
    255        
     205        int rc;
     206
     207        printf(NAME ": HelenOS loopback IP link provider\n");
     208
     209        if (log_init(NAME) != EOK) {
     210                printf(NAME ": Failed to initialize logging.\n");
     211                return 1;
     212        }
     213
    256214        rc = loopip_init();
    257215        if (rc != EOK)
    258                 return rc;
    259        
    260         printf("%s: Accepting connections.\n", NAME);
     216                return 1;
     217
     218        printf(NAME ": Accepting connections.\n");
    261219        task_retval(0);
    262220        async_manager();
    263        
     221
    264222        /* Not reached */
    265223        return 0;
Note: See TracChangeset for help on using the changeset viewer.