1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Kay Sievers, Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "timesyncd-server.h"
24 int server_address_new(
27 const union sockaddr_union *sockaddr,
30 ServerAddress *a, *tail;
34 assert(socklen >= offsetof(struct sockaddr, sa_data));
35 assert(socklen <= sizeof(union sockaddr_union));
37 a = new0(ServerAddress, 1);
41 memcpy(&a->sockaddr, sockaddr, socklen);
44 LIST_FIND_TAIL(addresses, n->addresses, tail);
45 LIST_INSERT_AFTER(addresses, n->addresses, tail, a);
54 ServerAddress* server_address_free(ServerAddress *a) {
59 LIST_REMOVE(addresses, a->name->addresses, a);
61 if (a->name->manager && a->name->manager->current_server_address == a)
62 manager_set_server_address(a->name->manager, NULL);
80 n = new0(ServerName, 1);
85 n->string = strdup(string);
91 if (type == SERVER_SYSTEM) {
92 LIST_FIND_TAIL(names, m->system_servers, tail);
93 LIST_INSERT_AFTER(names, m->system_servers, tail, n);
94 } else if (type == SERVER_LINK) {
95 LIST_FIND_TAIL(names, m->link_servers, tail);
96 LIST_INSERT_AFTER(names, m->link_servers, tail, n);
97 } else if (type == SERVER_FALLBACK) {
98 LIST_FIND_TAIL(names, m->fallback_servers, tail);
99 LIST_INSERT_AFTER(names, m->fallback_servers, tail, n);
101 assert_not_reached("Unknown server type");
105 if (type != SERVER_FALLBACK &&
106 m->current_server_name &&
107 m->current_server_name->type == SERVER_FALLBACK)
108 manager_set_server_name(m, NULL);
110 log_debug("Added new server %s.", string);
118 ServerName *server_name_free(ServerName *n) {
122 server_name_flush_addresses(n);
125 if (n->type == SERVER_SYSTEM)
126 LIST_REMOVE(names, n->manager->system_servers, n);
127 else if (n->type == SERVER_LINK)
128 LIST_REMOVE(names, n->manager->link_servers, n);
129 else if (n->type == SERVER_FALLBACK)
130 LIST_REMOVE(names, n->manager->fallback_servers, n);
132 assert_not_reached("Unknown server type");
134 if (n->manager->current_server_name == n)
135 manager_set_server_name(n->manager, NULL);
138 log_debug("Removed server %s.", n->string);
146 void server_name_flush_addresses(ServerName *n) {
150 server_address_free(n->addresses);