| 1 | /*
|
|---|
| 2 | * Copyright (c) 2013 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup nconfsrv
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file
|
|---|
| 34 | * @brief Network configuration Service
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <adt/list.h>
|
|---|
| 38 | #include <async.h>
|
|---|
| 39 | #include <errno.h>
|
|---|
| 40 | #include <fibril_synch.h>
|
|---|
| 41 | #include <inet/dhcp.h>
|
|---|
| 42 | #include <inet/inetcfg.h>
|
|---|
| 43 | #include <io/log.h>
|
|---|
| 44 | #include <ipc/inet.h>
|
|---|
| 45 | #include <ipc/services.h>
|
|---|
| 46 | #include <loc.h>
|
|---|
| 47 | #include <stdio.h>
|
|---|
| 48 | #include <stdlib.h>
|
|---|
| 49 | #include <sys/types.h>
|
|---|
| 50 | #include "iplink.h"
|
|---|
| 51 | #include "nconfsrv.h"
|
|---|
| 52 |
|
|---|
| 53 | #define NAME "nconfsrv"
|
|---|
| 54 |
|
|---|
| 55 | static void ncs_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
|
|---|
| 56 |
|
|---|
| 57 | static int ncs_init(void)
|
|---|
| 58 | {
|
|---|
| 59 | service_id_t sid;
|
|---|
| 60 | int rc;
|
|---|
| 61 |
|
|---|
| 62 | log_msg(LOG_DEFAULT, LVL_DEBUG, "ncs_init()");
|
|---|
| 63 |
|
|---|
| 64 | rc = inetcfg_init();
|
|---|
| 65 | if (rc != EOK) {
|
|---|
| 66 | log_msg(LOG_DEFAULT, LVL_ERROR, "Error contacting inet "
|
|---|
| 67 | "configuration service.");
|
|---|
| 68 | return EIO;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | rc = dhcp_init();
|
|---|
| 72 | if (rc != EOK) {
|
|---|
| 73 | log_msg(LOG_DEFAULT, LVL_ERROR, "Error contacting dhcp "
|
|---|
| 74 | "configuration service.");
|
|---|
| 75 | return EIO;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | async_set_client_connection(ncs_client_conn);
|
|---|
| 79 |
|
|---|
| 80 | rc = loc_server_register(NAME);
|
|---|
| 81 | if (rc != EOK) {
|
|---|
| 82 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc);
|
|---|
| 83 | return EEXIST;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | rc = loc_service_register(SERVICE_NAME_NETCONF, &sid);
|
|---|
| 87 | if (rc != EOK) {
|
|---|
| 88 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
|
|---|
| 89 | return EEXIST;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | rc = ncs_link_discovery_start();
|
|---|
| 93 | if (rc != EOK)
|
|---|
| 94 | return EEXIST;
|
|---|
| 95 |
|
|---|
| 96 | return EOK;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | static void ncs_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
|---|
| 100 | {
|
|---|
| 101 | async_answer_0(iid, ENOTSUP);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | int main(int argc, char *argv[])
|
|---|
| 105 | {
|
|---|
| 106 | int rc;
|
|---|
| 107 |
|
|---|
| 108 | printf(NAME ": HelenOS Network configuration service\n");
|
|---|
| 109 |
|
|---|
| 110 | if (log_init(NAME) != EOK) {
|
|---|
| 111 | printf(NAME ": Failed to initialize logging.\n");
|
|---|
| 112 | return 1;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | rc = ncs_init();
|
|---|
| 116 | if (rc != EOK)
|
|---|
| 117 | return 1;
|
|---|
| 118 |
|
|---|
| 119 | printf(NAME ": Accepting connections.\n");
|
|---|
| 120 | task_retval(0);
|
|---|
| 121 | async_manager();
|
|---|
| 122 |
|
|---|
| 123 | /* Not reached */
|
|---|
| 124 | return 0;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | /** @}
|
|---|
| 128 | */
|
|---|