Changeset bdae198 in mainline for uspace/lib


Ignore:
Timestamp:
2013-08-04T12:01:10Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ea509069
Parents:
b08879c2 (diff), d856110 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Location:
uspace/lib
Files:
16 edited

Legend:

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

    rb08879c2 rbdae198  
    6767}
    6868
    69 int dnsr_name2host(const char *name, dnsr_hostinfo_t **rinfo)
     69int dnsr_name2host(const char *name, dnsr_hostinfo_t **rinfo, uint16_t af)
    7070{
    7171        dnsr_hostinfo_t *info = calloc(1, sizeof(dnsr_hostinfo_t));
     
    7676       
    7777        ipc_call_t answer;
    78         aid_t req = async_send_0(exch, DNSR_NAME2HOST, &answer);
     78        aid_t req = async_send_1(exch, DNSR_NAME2HOST, (sysarg_t) af,
     79            &answer);
    7980       
    8081        int rc = async_data_write_start(exch, name, str_size(name));
  • uspace/lib/c/generic/inet/addr.c

    rb08879c2 rbdae198  
    5252};
    5353
     54static const addr48_t inet_addr48_solicited_node = {
     55        0x33, 0x33, 0xff, 0, 0, 0
     56};
     57
    5458static const inet_addr_t inet_addr_any_addr = {
    5559        .family = AF_INET,
     
    7074{
    7175        memcpy(dst, src, 16);
     76}
     77
     78int addr48_compare(const addr48_t a, const addr48_t b)
     79{
     80        return memcmp(a, b, 6);
     81}
     82
     83int addr128_compare(const addr128_t a, const addr128_t b)
     84{
     85        return memcmp(a, b, 16);
     86}
     87
     88/** Compute solicited node MAC multicast address from target IPv6 address
     89 *
     90 * @param ip  Target IPv6 address
     91 * @param mac Solicited MAC address to be assigned
     92 *
     93 */
     94void addr48_solicited_node(const addr128_t ip, addr48_t mac)
     95{
     96        memcpy(mac, inet_addr48_solicited_node, 3);
     97        memcpy(mac + 3, ip + 13, 3);
    7298}
    7399
     
    212238}
    213239
     240void inet_addr_naddr(const inet_addr_t *addr, uint8_t prefix,
     241    inet_naddr_t *naddr)
     242{
     243        naddr->family = addr->family;
     244        memcpy(naddr->addr6, addr->addr6, 16);
     245        naddr->prefix = prefix;
     246}
     247
    214248void inet_addr_any(inet_addr_t *addr)
    215249{
     
    234268                return (a->addr == b->addr);
    235269        case AF_INET6:
    236                 return memcmp(&a->addr6, &b->addr6, 16);
     270                return addr128_compare(a->addr6, b->addr6);
    237271        default:
    238272                return 0;
     
    245279            (inet_addr_compare(addr, &inet_addr_any_addr)) ||
    246280            (inet_addr_compare(addr, &inet_addr_any_addr6)));
     281}
     282
     283int inet_naddr_compare(const inet_naddr_t *naddr, const inet_addr_t *addr)
     284{
     285        if (naddr->family != addr->family)
     286                return 0;
     287       
     288        switch (naddr->family) {
     289        case AF_INET:
     290                return (naddr->addr == addr->addr);
     291        case AF_INET6:
     292                return addr128_compare(naddr->addr6, addr->addr6);
     293        default:
     294                return 0;
     295        }
    247296}
    248297
  • uspace/lib/c/generic/inetping6.c

    rb08879c2 rbdae198  
    7979       
    8080        ipc_call_t answer;
    81         aid_t req = async_send_3(exch, INETPING6_SEND, (sysarg_t) sdu->src,
    82             (sysarg_t) sdu->dest, sdu->seq_no, &answer);
    83         sysarg_t retval = async_data_write_start(exch, sdu->data, sdu->size);
     81        aid_t req = async_send_1(exch, INETPING6_SEND, sdu->seq_no, &answer);
     82       
     83        int rc = async_data_write_start(exch, &sdu->src, sizeof(addr128_t));
     84        if (rc != EOK) {
     85                async_exchange_end(exch);
     86                async_forget(req);
     87                return rc;
     88        }
     89       
     90        rc = async_data_write_start(exch, &sdu->dest, sizeof(addr128_t));
     91        if (rc != EOK) {
     92                async_exchange_end(exch);
     93                async_forget(req);
     94                return rc;
     95        }
     96       
     97        rc = async_data_write_start(exch, sdu->data, sdu->size);
    8498       
    8599        async_exchange_end(exch);
    86100       
    87         if (retval != EOK) {
    88                 async_forget(req);
    89                 return retval;
    90         }
    91        
     101        if (rc != EOK) {
     102                async_forget(req);
     103                return rc;
     104        }
     105       
     106        sysarg_t retval;
    92107        async_wait_for(req, &retval);
    93         return retval;
     108       
     109        return (int) retval;
    94110}
    95111
     
    142158        }
    143159       
    144         if (size != sizeof(inet_addr_t)) {
     160        if (size != sizeof(addr128_t)) {
    145161                async_answer_0(callid, EINVAL);
    146162                async_answer_0(iid, EINVAL);
     
    161177        }
    162178       
    163         if (size != sizeof(inet_addr_t)) {
     179        if (size != sizeof(addr128_t)) {
    164180                async_answer_0(callid, EINVAL);
    165181                async_answer_0(iid, EINVAL);
  • uspace/lib/c/generic/iplink.c

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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/generic/net/socket_parse.c

    rb08879c2 rbdae198  
    5353int socket_parse_address_family(const char *name, int *af)
    5454{
    55         if (str_lcmp(name, "AF_INET", 7) == 0) {
    56                 *af = AF_INET;
     55        if (str_lcmp(name, "AF_INET6", 8) == 0) {
     56                *af = AF_INET6;
    5757                return EOK;
    5858        }
    5959       
    60         if (str_lcmp(name, "AF_INET6", 8) == 0) {
    61                 *af = AF_INET6;
     60        if (str_lcmp(name, "AF_INET", 7) == 0) {
     61                *af = AF_INET;
    6262                return EOK;
    6363        }
  • uspace/lib/c/include/inet/addr.h

    rb08879c2 rbdae198  
    7373extern void addr128(const addr128_t, addr128_t);
    7474
     75extern int addr48_compare(const addr48_t, const addr48_t);
     76extern int addr128_compare(const addr128_t, const addr128_t);
     77
     78extern void addr48_solicited_node(const addr128_t, addr48_t);
     79
    7580extern void host2addr128_t_be(const addr128_t, addr128_t);
    7681extern void addr128_t_be2host(const addr128_t, addr128_t);
     
    8792extern int inet_addr_family(const char *, uint16_t *);
    8893extern void inet_naddr_addr(const inet_naddr_t *, inet_addr_t *);
     94extern void inet_addr_naddr(const inet_addr_t *, uint8_t, inet_naddr_t *);
    8995
    9096extern void inet_addr_any(inet_addr_t *);
     
    94100extern int inet_addr_is_any(const inet_addr_t *);
    95101
     102extern int inet_naddr_compare(const inet_naddr_t *, const inet_addr_t *);
    96103extern int inet_naddr_compare_mask(const inet_naddr_t *, const inet_addr_t *);
    97104
  • uspace/lib/c/include/inet/dnsr.h

    rb08879c2 rbdae198  
    5151
    5252extern int dnsr_init(void);
    53 extern int dnsr_name2host(const char *, dnsr_hostinfo_t **);
     53extern int dnsr_name2host(const char *, dnsr_hostinfo_t **, uint16_t);
    5454extern void dnsr_hostinfo_destroy(dnsr_hostinfo_t *);
    5555extern int dnsr_get_srvaddr(inet_addr_t *);
  • uspace/lib/c/include/inet/iplink.h

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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
  • uspace/lib/posix/include/posix/stdio.h

    rb08879c2 rbdae198  
    6565
    6666#define BUFSIZ  4096
    67 #define SEEK_SET  0
    68 #define SEEK_CUR  1
    69 #define SEEK_END  2
    7067
    7168typedef struct _IO_FILE FILE;
  • uspace/lib/posix/include/posix/stdlib.h

    rb08879c2 rbdae198  
    4646        #define NULL  ((void *) 0)
    4747#endif
     48
     49#define RAND_MAX  714025
    4850
    4951/* Process Termination */
     
    122124extern int __POSIX_DEF__(mkstemp)(char *tmpl);
    123125
     126/* Pseudo-random number generator */
     127extern int __POSIX_DEF__(rand)(void);
     128extern void __POSIX_DEF__(srand)(unsigned int seed);
     129
    124130/* Legacy Declarations */
    125131extern char *__POSIX_DEF__(mktemp)(char *tmpl);
  • uspace/lib/posix/include/posix/unistd.h

    rb08879c2 rbdae198  
    4444#include "stddef.h"
    4545
     46#define SEEK_SET  0
     47#define SEEK_CUR  1
     48#define SEEK_END  2
     49
    4650/* Process Termination */
    4751#define _exit exit
     
    7781extern ssize_t __POSIX_DEF__(read)(int fildes, void *buf, size_t nbyte);
    7882extern ssize_t __POSIX_DEF__(write)(int fildes, const void *buf, size_t nbyte);
     83extern __POSIX_DEF__(off_t) __POSIX_DEF__(lseek)(int fildes,
     84    __POSIX_DEF__(off_t) offset, int whence);
    7985extern int __POSIX_DEF__(fsync)(int fildes);
    8086extern int __POSIX_DEF__(ftruncate)(int fildes, __POSIX_DEF__(off_t) length);
  • uspace/lib/posix/source/stdlib.c

    rb08879c2 rbdae198  
    394394
    395395/**
     396 * Generate a pseudo random integer in the range 0 to RAND_MAX inclusive.
     397 *
     398 * @return The pseudo random integer.
     399 */
     400int posix_rand(void)
     401{
     402        return (int) random();
     403}
     404
     405/**
     406 * Initialize a new sequence of pseudo-random integers.
     407 *
     408 * @param seed The seed of the new sequence.
     409 */
     410void posix_srand(unsigned int seed)
     411{
     412        srandom(seed);
     413}
     414
     415/**
    396416 * Creates and opens an unique temporary file from template.
    397417 *
  • uspace/lib/posix/source/unistd.c

    rb08879c2 rbdae198  
    221221{
    222222        return errnify(write, fildes, buf, nbyte);
     223}
     224
     225/**
     226 * Reposition read/write file offset
     227 *
     228 * @param fildes File descriptor of the opened file.
     229 * @param offset New offset in the file.
     230 * @param whence The position from which the offset argument is specified.
     231 * @return Upon successful completion, returns the resulting offset
     232 *         as measured in bytes from the beginning of the file, -1 otherwise.
     233 */
     234posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence)
     235{
     236        return errnify(lseek, fildes, offset, whence);
    223237}
    224238
Note: See TracChangeset for help on using the changeset viewer.