Changeset a17356fd in mainline for uspace/lib/c


Ignore:
Timestamp:
2013-07-12T15:33:20Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bb9b0c6
Parents:
f5f79cd
Message:

iplink IPv6 datagram support
rudimentary IPv6 support (sans fragmentation)

Location:
uspace/lib/c
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/iplink.c

    rf5f79cd ra17356fd  
    8686       
    8787        ipc_call_t answer;
    88         aid_t req = async_send_0(exch, IPLINK_SEND, &answer);
    89        
    90         int rc = async_data_write_start(exch, &sdu->src, sizeof(inet_addr_t));
     88        aid_t req = async_send_2(exch, IPLINK_SEND, (sysarg_t) sdu->src,
     89            (sysarg_t) sdu->dest, &answer);
     90       
     91        int rc = async_data_write_start(exch, sdu->data, sdu->size);
     92       
     93        async_exchange_end(exch);
     94       
     95        if (rc != EOK) {
     96                async_forget(req);
     97                return rc;
     98        }
     99       
     100        sysarg_t retval;
     101        async_wait_for(req, &retval);
     102       
     103        return (int) retval;
     104}
     105
     106int iplink_send6(iplink_t *iplink, iplink_sdu6_t *sdu)
     107{
     108        async_exch_t *exch = async_exchange_begin(iplink->sess);
     109       
     110        ipc_call_t answer;
     111        aid_t req = async_send_0(exch, IPLINK_SEND6, &answer);
     112       
     113        int rc = async_data_write_start(exch, &sdu->dest, sizeof(addr48_t));
    91114        if (rc != EOK) {
    92115                async_exchange_end(exch);
     
    95118        }
    96119       
    97         rc = async_data_write_start(exch, &sdu->dest, sizeof(inet_addr_t));
    98         if (rc != EOK) {
    99                 async_exchange_end(exch);
    100                 async_forget(req);
    101                 return rc;
    102         }
    103        
    104120        rc = async_data_write_start(exch, sdu->data, sdu->size);
    105121       
     
    119135int iplink_get_mtu(iplink_t *iplink, size_t *rmtu)
    120136{
     137        async_exch_t *exch = async_exchange_begin(iplink->sess);
     138       
    121139        sysarg_t mtu;
    122         async_exch_t *exch = async_exchange_begin(iplink->sess);
    123 
    124140        int rc = async_req_0_1(exch, IPLINK_GET_MTU, &mtu);
    125         async_exchange_end(exch);
    126 
     141       
     142        async_exchange_end(exch);
     143       
    127144        if (rc != EOK)
    128145                return rc;
    129 
     146       
    130147        *rmtu = mtu;
    131148        return EOK;
     149}
     150
     151int iplink_get_mac48(iplink_t *iplink, addr48_t *mac)
     152{
     153        async_exch_t *exch = async_exchange_begin(iplink->sess);
     154       
     155        ipc_call_t answer;
     156        aid_t req = async_send_0(exch, IPLINK_GET_MAC48, &answer);
     157       
     158        int rc = async_data_read_start(exch, mac, sizeof(addr48_t));
     159       
     160        loc_exchange_end(exch);
     161       
     162        if (rc != EOK) {
     163                async_forget(req);
     164                return rc;
     165        }
     166       
     167        sysarg_t retval;
     168        async_wait_for(req, &retval);
     169       
     170        return (int) retval;
    132171}
    133172
  • uspace/lib/c/generic/iplink_srv.c

    rf5f79cd ra17356fd  
    5050}
    5151
     52static void iplink_get_mac48_srv(iplink_srv_t *srv, ipc_callid_t iid,
     53    ipc_call_t *icall)
     54{
     55        addr48_t mac;
     56        int rc = srv->ops->get_mac48(srv, &mac);
     57        if (rc != EOK) {
     58                async_answer_0(iid, rc);
     59                return;
     60        }
     61       
     62        ipc_callid_t callid;
     63        size_t size;
     64        if (!async_data_read_receive(&callid, &size)) {
     65                async_answer_0(callid, EREFUSED);
     66                async_answer_0(iid, EREFUSED);
     67                return;
     68        }
     69       
     70        if (size != sizeof(addr48_t)) {
     71                async_answer_0(callid, EINVAL);
     72                async_answer_0(iid, EINVAL);
     73                return;
     74        }
     75       
     76        rc = async_data_read_finalize(callid, &mac, size);
     77        if (rc != EOK)
     78                async_answer_0(callid, rc);
     79       
     80        async_answer_0(iid, (sysarg_t) rc);
     81}
     82
    5283static void iplink_addr_add_srv(iplink_srv_t *srv, ipc_callid_t iid,
    5384    ipc_call_t *icall)
     
    111142        iplink_sdu_t sdu;
    112143       
     144        sdu.src = IPC_GET_ARG1(*icall);
     145        sdu.dest = IPC_GET_ARG2(*icall);
     146       
     147        int rc = async_data_write_accept(&sdu.data, false, 0, 0, 0,
     148            &sdu.size);
     149        if (rc != EOK) {
     150                async_answer_0(iid, rc);
     151                return;
     152        }
     153       
     154        rc = srv->ops->send(srv, &sdu);
     155        free(sdu.data);
     156        async_answer_0(iid, rc);
     157}
     158
     159static void iplink_send6_srv(iplink_srv_t *srv, ipc_callid_t iid,
     160    ipc_call_t *icall)
     161{
     162        iplink_sdu6_t sdu;
     163       
    113164        ipc_callid_t callid;
    114165        size_t size;
     
    119170        }
    120171       
    121         if (size != sizeof(inet_addr_t)) {
     172        if (size != sizeof(addr48_t)) {
    122173                async_answer_0(callid, EINVAL);
    123174                async_answer_0(iid, EINVAL);
     
    125176        }
    126177       
    127         int rc = async_data_write_finalize(callid, &sdu.src, size);
     178        int rc = async_data_write_finalize(callid, &sdu.dest, size);
    128179        if (rc != EOK) {
    129180                async_answer_0(callid, (sysarg_t) rc);
     
    131182        }
    132183       
    133         if (!async_data_write_receive(&callid, &size)) {
    134                 async_answer_0(callid, EREFUSED);
    135                 async_answer_0(iid, EREFUSED);
    136                 return;
    137         }
    138        
    139         if (size != sizeof(inet_addr_t)) {
    140                 async_answer_0(callid, EINVAL);
    141                 async_answer_0(iid, EINVAL);
    142                 return;
    143         }
    144        
    145         rc = async_data_write_finalize(callid, &sdu.dest, size);
    146         if (rc != EOK) {
    147                 async_answer_0(callid, (sysarg_t) rc);
    148                 async_answer_0(iid, (sysarg_t) rc);
    149         }
    150        
    151184        rc = async_data_write_accept(&sdu.data, false, 0, 0, 0,
    152185            &sdu.size);
    153         if (rc != EOK)
    154                 return;
    155        
    156         rc = srv->ops->send(srv, &sdu);
     186        if (rc != EOK) {
     187                async_answer_0(iid, rc);
     188                return;
     189        }
     190       
     191        rc = srv->ops->send6(srv, &sdu);
    157192        free(sdu.data);
    158193        async_answer_0(iid, rc);
     
    170205int iplink_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    171206{
    172         iplink_srv_t *srv = (iplink_srv_t *)arg;
     207        iplink_srv_t *srv = (iplink_srv_t *) arg;
    173208        int rc;
    174209       
     
    214249                        iplink_get_mtu_srv(srv, callid, &call);
    215250                        break;
     251                case IPLINK_GET_MAC48:
     252                        iplink_get_mac48_srv(srv, callid, &call);
     253                        break;
    216254                case IPLINK_SEND:
    217255                        iplink_send_srv(srv, callid, &call);
     256                        break;
     257                case IPLINK_SEND6:
     258                        iplink_send6_srv(srv, callid, &call);
    218259                        break;
    219260                case IPLINK_ADDR_ADD:
  • uspace/lib/c/include/inet/iplink.h

    rf5f79cd ra17356fd  
    4747} iplink_t;
    4848
    49 /** Internet link Service Data Unit */
     49/** IPv4 link Service Data Unit */
    5050typedef struct {
    5151        /** Local source address */
    52         inet_addr_t src;
     52        addr32_t src;
    5353        /** Local destination address */
    54         inet_addr_t dest;
     54        addr32_t dest;
    5555        /** Serialized IP packet */
    5656        void *data;
     
    5858        size_t size;
    5959} iplink_sdu_t;
     60
     61/** IPv6 link Service Data Unit */
     62typedef struct {
     63        /** Local MAC destination address */
     64        addr48_t dest;
     65        /** Serialized IP packet */
     66        void *data;
     67        /** Size of @c data in bytes */
     68        size_t size;
     69} iplink_sdu6_t;
    6070
    6171/** Internet link receive Service Data Unit */
     
    7484extern void iplink_close(iplink_t *);
    7585extern int iplink_send(iplink_t *, iplink_sdu_t *);
     86extern int iplink_send6(iplink_t *, iplink_sdu6_t *);
    7687extern int iplink_addr_add(iplink_t *, inet_addr_t *);
    7788extern int iplink_addr_remove(iplink_t *, inet_addr_t *);
    7889extern int iplink_get_mtu(iplink_t *, size_t *);
     90extern int iplink_get_mac48(iplink_t *, addr48_t *);
    7991
    8092#endif
  • uspace/lib/c/include/inet/iplink_srv.h

    rf5f79cd ra17356fd  
    5757        int (*close)(iplink_srv_t *);
    5858        int (*send)(iplink_srv_t *, iplink_sdu_t *);
     59        int (*send6)(iplink_srv_t *, iplink_sdu6_t *);
    5960        int (*get_mtu)(iplink_srv_t *, size_t *);
     61        int (*get_mac48)(iplink_srv_t *, addr48_t *);
    6062        int (*addr_add)(iplink_srv_t *, inet_addr_t *);
    6163        int (*addr_remove)(iplink_srv_t *, inet_addr_t *);
  • uspace/lib/c/include/ipc/iplink.h

    rf5f79cd ra17356fd  
    4040typedef enum {
    4141        IPLINK_GET_MTU = IPC_FIRST_USER_METHOD,
     42        IPLINK_GET_MAC48,
    4243        IPLINK_SEND,
     44        IPLINK_SEND6,
    4345        IPLINK_ADDR_ADD,
    4446        IPLINK_ADDR_REMOVE
Note: See TracChangeset for help on using the changeset viewer.