~as-s/helenos/ipv6

« back to all changes in this revision

Viewing changes to uspace/srv/net/inetsrv/inetcfg.c

  • Committer: Anthony Steinhauser
  • Date: 2013-07-08 01:07:36 UTC
  • Revision ID: as@strmilov.cz-20130708010736-pbvrszhamp0v64ez
HelenOS networking stack supports IPv6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (c) 2012 Jiri Svoboda
 
3
 * Copyright (c) 2013 Antonin Steinhauser
3
4
 * All rights reserved.
4
5
 *
5
6
 * Redistribution and use in source and binary forms, with or without
50
51
#include "inetcfg.h"
51
52
#include "sroute.h"
52
53
 
53
 
static int inetcfg_addr_create_static(char *name, in_naddr_t *naddr,
 
54
static int inetcfg_addr_create_static(char *name, in6_naddr_t *naddr,
54
55
    sysarg_t link_id, sysarg_t *addr_id)
55
56
{
56
57
        inet_link_t *ilink;
81
82
                return rc;
82
83
        }
83
84
 
84
 
        iaddr.s_addr = addr->naddr.s_addr;
85
 
        rc = iplink_addr_add(ilink->iplink, &iaddr);
 
85
        if (is_mapped((in6_addr_t *)&addr->naddr)) {
 
86
                ipv6_to_ipv4(&iaddr, (in6_addr_t *)&addr->naddr);
 
87
                rc = iplink_addr_add(ilink->iplink, &iaddr);
 
88
        }
 
89
 
86
90
        if (rc != EOK) {
87
91
                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed setting IP address on internet link.");
88
92
                inet_addrobj_remove(addr);
96
100
static int inetcfg_addr_delete(sysarg_t addr_id)
97
101
{
98
102
        inet_addrobj_t *addr;
 
103
        in_addr_t iaddr;
99
104
 
100
105
        addr = inet_addrobj_get_by_id(addr_id);
101
106
        if (addr == NULL)
102
107
                return ENOENT;
103
108
 
 
109
        if (is_mapped((in6_addr_t *)&addr->naddr)) {
 
110
                ipv6_to_ipv4(&iaddr, (in6_addr_t *)&addr->naddr);
 
111
                (void) iplink_addr_remove(addr->ilink->iplink, &iaddr);
 
112
        }
 
113
 
104
114
        inet_addrobj_remove(addr);
105
115
        inet_addrobj_delete(addr);
106
116
 
172
182
        return EOK;
173
183
}
174
184
 
175
 
static int inetcfg_sroute_create(char *name, in_naddr_t *dest,
176
 
    in_addr_t *router, sysarg_t *sroute_id)
 
185
static int inetcfg_sroute_create(char *name, in6_naddr_t *dest,
 
186
    in6_addr_t *router, sysarg_t *sroute_id)
177
187
{
178
188
        inet_sroute_t *sroute;
179
189
 
239
249
    ipc_call_t *call)
240
250
{
241
251
        char *name;
242
 
        in_naddr_t naddr;
 
252
        in6_naddr_t naddr;
243
253
        sysarg_t link_id;
244
254
        sysarg_t addr_id;
245
255
        int rc;
254
264
                return;
255
265
        }
256
266
 
257
 
        if (size != 4) {
 
267
        if (size != sizeof(in6_addr_t)) {
258
268
                async_answer_0(rcallid, EINVAL);
259
269
                async_answer_0(callid, EINVAL);
260
270
                return;
261
271
        }
262
272
 
263
 
        rc = async_data_write_finalize(rcallid, &naddr.s_addr, 4);
 
273
        rc = async_data_write_finalize(rcallid, naddr.s6_addr,
 
274
            sizeof(in6_addr_t));
264
275
 
265
276
        if (rc != EOK) {
266
277
                async_answer_0(rcallid, rc);
324
335
                return;
325
336
        }
326
337
 
327
 
        if (size != 4) {
 
338
        if (size != sizeof(in6_addr_t)) {
328
339
                async_answer_0(rcallid, EINVAL);
329
340
                async_answer_0(callid, EINVAL);
330
341
                return;
331
342
        }
332
343
 
333
 
        sysarg_t retval = async_data_read_finalize(rcallid, &ainfo.naddr.s_addr, 4);
 
344
        sysarg_t retval = async_data_read_finalize(rcallid,
 
345
            ainfo.naddr.s6_addr, sizeof(in6_addr_t));
334
346
 
335
347
        if (rc != EOK) {
336
348
                async_answer_0(callid, rc);
513
525
    ipc_call_t *call)
514
526
{
515
527
        char *name;
516
 
        in_naddr_t dest;
517
 
        in_addr_t router;
 
528
        in6_naddr_t dest;
 
529
        in6_addr_t router;
518
530
        sysarg_t sroute_id;
519
531
        int rc;
520
532
        ipc_callid_t rcallid;
528
540
                return;
529
541
        }
530
542
 
531
 
        if (size != 4) {
 
543
        if (size != sizeof(in6_addr_t)) {
532
544
                async_answer_0(rcallid, EINVAL);
533
545
                async_answer_0(callid, EINVAL);
534
546
                return;
535
547
        }
536
548
 
537
 
        rc = async_data_write_finalize(rcallid, &dest.s_addr, 4);
 
549
        rc = async_data_write_finalize(rcallid, dest.s6_addr,
 
550
            sizeof(in6_addr_t));
538
551
 
539
552
        if (rc != EOK) {
540
553
                async_answer_0(callid, rc);
547
560
                return;
548
561
        }
549
562
 
550
 
        if (size != 4) {
 
563
        if (size != sizeof(in6_addr_t)) {
551
564
                async_answer_0(rcallid, EINVAL);
552
565
                async_answer_0(callid, EINVAL);
553
566
                return;
554
567
        }
555
568
 
556
 
        rc = async_data_write_finalize(rcallid, &router.s_addr, 4);
 
569
        rc = async_data_write_finalize(rcallid, router.s6_addr,
 
570
            sizeof(in6_addr_t));
557
571
 
558
572
        if (rc != EOK) {
559
573
                async_answer_0(callid, rc);
567
581
                return;
568
582
        }
569
583
 
570
 
        dest.bits   = IPC_GET_ARG1(*call);
 
584
        dest.bits = IPC_GET_ARG1(*call);
571
585
 
572
586
        sroute_id = 0;
573
587
        rc = inetcfg_sroute_create(name, &dest, &router, &sroute_id);
600
614
        sroute_id = IPC_GET_ARG1(*call);
601
615
        log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_srv()");
602
616
 
603
 
        srinfo.dest.s_addr = 0;
 
617
        memcpy(srinfo.dest.s6_addr, in6addr_any.s6_addr, sizeof(in6_addr_t));
604
618
        srinfo.dest.bits = 0;
605
 
        srinfo.router.s_addr = 0;
 
619
        srinfo.router = in6addr_any;
606
620
        srinfo.name = NULL;
607
621
 
608
622
        rc = inetcfg_sroute_get(sroute_id, &srinfo);
617
631
                return;
618
632
        }
619
633
 
620
 
        if (size != 4) {
 
634
        if (size != sizeof(in6_addr_t)) {
621
635
                async_answer_0(rcallid, EINVAL);
622
636
                async_answer_0(callid, EINVAL);
623
637
                return;
624
638
        }
625
639
 
626
 
        rc = async_data_read_finalize(rcallid, &srinfo.dest.s_addr, 4);
 
640
        rc = async_data_read_finalize(rcallid, srinfo.dest.s6_addr,
 
641
            sizeof(in6_addr_t));
627
642
 
628
643
        if (rc != EOK) {
629
644
                async_answer_0(callid, rc);
636
651
                return;
637
652
        }
638
653
 
639
 
        if (size != 4) {
 
654
        if (size != sizeof(in6_addr_t)) {
640
655
                async_answer_0(rcallid, EINVAL);
641
656
                async_answer_0(callid, EINVAL);
642
657
                return;
643
658
        }
644
659
 
645
 
        rc = async_data_read_finalize(rcallid, &srinfo.router.s_addr, 4);
 
660
        rc = async_data_read_finalize(rcallid, srinfo.router.s6_addr,
 
661
            sizeof(in6_addr_t));
646
662
 
647
663
        if (rc != EOK) {
648
664
                async_answer_0(callid, rc);