]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/timesync/timesyncd-server.c
2 This file is part of systemd.
4 Copyright 2014 Kay Sievers, Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "alloc-util.h"
21 #include "timesyncd-server.h"
23 int server_address_new(
26 const union sockaddr_union
*sockaddr
,
29 ServerAddress
*a
, *tail
;
33 assert(socklen
>= offsetof(struct sockaddr
, sa_data
));
34 assert(socklen
<= sizeof(union sockaddr_union
));
36 a
= new0(ServerAddress
, 1);
40 memcpy(&a
->sockaddr
, sockaddr
, socklen
);
43 LIST_FIND_TAIL(addresses
, n
->addresses
, tail
);
44 LIST_INSERT_AFTER(addresses
, n
->addresses
, tail
, a
);
53 ServerAddress
* server_address_free(ServerAddress
*a
) {
58 LIST_REMOVE(addresses
, a
->name
->addresses
, a
);
60 if (a
->name
->manager
&& a
->name
->manager
->current_server_address
== a
)
61 manager_set_server_address(a
->name
->manager
, NULL
);
79 n
= new0(ServerName
, 1);
84 n
->string
= strdup(string
);
90 if (type
== SERVER_SYSTEM
) {
91 LIST_FIND_TAIL(names
, m
->system_servers
, tail
);
92 LIST_INSERT_AFTER(names
, m
->system_servers
, tail
, n
);
93 } else if (type
== SERVER_LINK
) {
94 LIST_FIND_TAIL(names
, m
->link_servers
, tail
);
95 LIST_INSERT_AFTER(names
, m
->link_servers
, tail
, n
);
96 } else if (type
== SERVER_FALLBACK
) {
97 LIST_FIND_TAIL(names
, m
->fallback_servers
, tail
);
98 LIST_INSERT_AFTER(names
, m
->fallback_servers
, tail
, n
);
100 assert_not_reached("Unknown server type");
104 if (type
!= SERVER_FALLBACK
&&
105 m
->current_server_name
&&
106 m
->current_server_name
->type
== SERVER_FALLBACK
)
107 manager_set_server_name(m
, NULL
);
109 log_debug("Added new server %s.", string
);
117 ServerName
*server_name_free(ServerName
*n
) {
121 server_name_flush_addresses(n
);
124 if (n
->type
== SERVER_SYSTEM
)
125 LIST_REMOVE(names
, n
->manager
->system_servers
, n
);
126 else if (n
->type
== SERVER_LINK
)
127 LIST_REMOVE(names
, n
->manager
->link_servers
, n
);
128 else if (n
->type
== SERVER_FALLBACK
)
129 LIST_REMOVE(names
, n
->manager
->fallback_servers
, n
);
131 assert_not_reached("Unknown server type");
133 if (n
->manager
->current_server_name
== n
)
134 manager_set_server_name(n
->manager
, NULL
);
137 log_debug("Removed server %s.", n
->string
);
145 void server_name_flush_addresses(ServerName
*n
) {
149 server_address_free(n
->addresses
);