source: mainline/uspace/srv/net/nconfsrv/nconfsrv.c@ bdd9e92

Last change on this file since bdd9e92 was 4c6fd56, checked in by Jiri Svoboda <jiri@…>, 2 years ago

loc_server_register() should be callable more than once (API only)

Now loc_server_register() returns a pointer to a loc_srv_t object,
that is then passed to loc_service_register() and
loc_service_add_to_cat().

Added loc_server_unregister() that unregisters the server
and frees the loc_srv_t object.

Updated all callers. The implementation, however, is a stub.
It is not actually possible to call loc_server_register() more
than once, yet.

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[7af0cc5]1/*
[4c6fd56]2 * Copyright (c) 2023 Jiri Svoboda
[7af0cc5]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>
[c1694b6b]40#include <str_error.h>
[7af0cc5]41#include <fibril_synch.h>
[bd88bee]42#include <inet/dhcp.h>
[7af0cc5]43#include <inet/inetcfg.h>
44#include <io/log.h>
45#include <ipc/inet.h>
46#include <ipc/services.h>
47#include <loc.h>
48#include <stdio.h>
49#include <stdlib.h>
[1c635d6]50#include <task.h>
[7af0cc5]51#include "iplink.h"
52#include "nconfsrv.h"
53
54#define NAME "nconfsrv"
55
[984a9ba]56static void ncs_client_conn(ipc_call_t *icall, void *arg);
[7af0cc5]57
[b7fd2a0]58static errno_t ncs_init(void)
[7af0cc5]59{
60 service_id_t sid;
[4c6fd56]61 loc_srv_t *srv;
[b7fd2a0]62 errno_t rc;
[7af0cc5]63
64 log_msg(LOG_DEFAULT, LVL_DEBUG, "ncs_init()");
65
66 rc = inetcfg_init();
67 if (rc != EOK) {
68 log_msg(LOG_DEFAULT, LVL_ERROR, "Error contacting inet "
69 "configuration service.");
70 return EIO;
71 }
72
[bd88bee]73 rc = dhcp_init();
74 if (rc != EOK) {
75 log_msg(LOG_DEFAULT, LVL_ERROR, "Error contacting dhcp "
76 "configuration service.");
77 return EIO;
78 }
79
[b688fd8]80 async_set_fallback_port_handler(ncs_client_conn, NULL);
[7af0cc5]81
[4c6fd56]82 rc = loc_server_register(NAME, &srv);
[7af0cc5]83 if (rc != EOK) {
[c1694b6b]84 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
[7af0cc5]85 return EEXIST;
86 }
87
[4c6fd56]88 rc = loc_service_register(srv, SERVICE_NAME_NETCONF, &sid);
[7af0cc5]89 if (rc != EOK) {
[4c6fd56]90 loc_server_unregister(srv);
[c1694b6b]91 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
[7af0cc5]92 return EEXIST;
93 }
94
95 rc = ncs_link_discovery_start();
[4c6fd56]96 if (rc != EOK) {
97 loc_service_unregister(srv, sid);
98 loc_server_unregister(srv);
[7af0cc5]99 return EEXIST;
[4c6fd56]100 }
[7af0cc5]101
102 return EOK;
103}
104
[984a9ba]105static void ncs_client_conn(ipc_call_t *icall, void *arg)
[7af0cc5]106{
[984a9ba]107 async_answer_0(icall, ENOTSUP);
[7af0cc5]108}
109
110int main(int argc, char *argv[])
111{
[b7fd2a0]112 errno_t rc;
[7af0cc5]113
114 printf(NAME ": HelenOS Network configuration service\n");
115
116 if (log_init(NAME) != EOK) {
117 printf(NAME ": Failed to initialize logging.\n");
118 return 1;
119 }
120
121 rc = ncs_init();
122 if (rc != EOK)
123 return 1;
124
125 printf(NAME ": Accepting connections.\n");
126 task_retval(0);
127 async_manager();
128
129 /* Not reached */
130 return 0;
131}
132
133/** @}
134 */
Note: See TracBrowser for help on using the repository browser.