| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "alloc-util.h" |
| 4 |
#include "bus-util.h" |
| 5 |
#include "extract-word.h" |
| 6 |
#include "hashmap.h" |
| 7 |
#include "networkd-address.h" |
| 8 |
#include "networkd-dhcp4.h" |
| 9 |
#include "networkd-dhcp6.h" |
| 10 |
#include "networkd-link.h" |
| 11 |
#include "networkd-setlink.h" |
| 12 |
#include "networkd-manager.h" |
| 13 |
#include "networkd-ndisc.h" |
| 14 |
#include "networkd-route.h" |
| 15 |
#include "networkd-wwan.h" |
| 16 |
#include "parse-util.h" |
| 17 |
#include "sd-dhcp-client.h" |
| 18 |
#include "sd-dhcp6-client.h" |
| 19 |
#include "sd-ndisc.h" |
| 20 |
#include "set.h" |
| 21 |
#include "string-util.h" |
| 22 |
|
| 23 |
Bearer* bearer_free(Bearer *b) { |
| 24 |
if (!b) |
| 25 |
return NULL; |
| 26 |
|
| 27 |
if (b->modem) { |
| 28 |
if (b->path) |
| 29 |
hashmap_remove_value(b->modem->bearers_by_path, b->path, b); |
| 30 |
if (b->name) |
| 31 |
hashmap_remove_value(b->modem->bearers_by_name, b->name, b); |
| 32 |
} |
| 33 |
|
| 34 |
sd_bus_slot_unref(b->slot_getall); |
| 35 |
|
| 36 |
free(b->path); |
| 37 |
free(b->name); |
| 38 |
free(b->apn); |
| 39 |
|
| 40 |
in_addr_full_free_array(b->dns, b->n_dns); |
| 41 |
|
| 42 |
return mfree(b); |
| 43 |
} |
| 44 |
|
| 45 |
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( |
| 46 |
bearer_hash_ops, |
| 47 |
char, |
| 48 |
string_hash_func, |
| 49 |
string_compare_func, |
| 50 |
Bearer, |
| 51 |
bearer_free); |
| 52 |
|
| 53 |
int bearer_new(Modem *modem, const char *path, Bearer **ret) { |
| 54 |
_cleanup_(bearer_freep) Bearer *b = NULL; |
| 55 |
_cleanup_free_ char *p = NULL; |
| 56 |
int r; |
| 57 |
|
| 58 |
assert(modem); |
| 59 |
assert(path); |
| 60 |
|
| 61 |
if (hashmap_contains(modem->bearers_by_path, path)) |
| 62 |
return -EEXIST; |
| 63 |
|
| 64 |
p = strdup(path); |
| 65 |
if (!p) |
| 66 |
return -ENOMEM; |
| 67 |
|
| 68 |
b = new(Bearer, 1); |
| 69 |
if (!b) |
| 70 |
return -ENOMEM; |
| 71 |
|
| 72 |
*b = (Bearer) { |
| 73 |
.modem = modem, |
| 74 |
.path = TAKE_PTR(p), |
| 75 |
}; |
| 76 |
|
| 77 |
r = hashmap_ensure_put(&modem->bearers_by_path, &bearer_hash_ops, b->path, b); |
| 78 |
if (r < 0) |
| 79 |
return r; |
| 80 |
|
| 81 |
if (ret) |
| 82 |
*ret = b; |
| 83 |
TAKE_PTR(b); |
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
int bearer_set_name(Bearer *b, const char *name) { |
| 88 |
Bearer *old; |
| 89 |
int r; |
| 90 |
|
| 91 |
assert(b); |
| 92 |
assert(b->modem); |
| 93 |
assert(name); |
| 94 |
|
| 95 |
if (streq_ptr(b->name, name)) |
| 96 |
return 0; |
| 97 |
|
| 98 |
if (b->name) |
| 99 |
hashmap_remove_value(b->modem->bearers_by_name, b->name, b); |
| 100 |
|
| 101 |
if (isempty(name)) { |
| 102 |
b->name = mfree(b->name); |
| 103 |
return 0; |
| 104 |
} |
| 105 |
|
| 106 |
r = free_and_strdup(&b->name, name); |
| 107 |
if (r < 0) |
| 108 |
return r; |
| 109 |
|
| 110 |
/* |
| 111 |
* FIXME: it is possible during reconnect that an interface is already |
| 112 |
* registered in the hash map: if simple connect options |
| 113 |
* are changed, e.g. externally modified .network file and then |
| 114 |
* reloaded with 'networkctl reload'. This may create a new bearer |
| 115 |
* attached to the same interface name, e.g. "wwan0". The order in which |
| 116 |
* we parse the bearer properties is undetermined and it can be that we |
| 117 |
* need to raplce the old one with the new one now, so only one bearer |
| 118 |
* with the given interface name exists. |
| 119 |
*/ |
| 120 |
old = hashmap_get(b->modem->bearers_by_name, name); |
| 121 |
if (old) { |
| 122 |
hashmap_remove_value(old->modem->bearers_by_name, name, old); |
| 123 |
old->name = mfree(old->name); |
| 124 |
} |
| 125 |
|
| 126 |
return hashmap_ensure_put(&b->modem->bearers_by_name, &bearer_hash_ops, b->name, b); |
| 127 |
} |
| 128 |
|
| 129 |
int bearer_get_by_path(Manager *manager, const char *path, Modem **ret_modem, Bearer **ret_bearer) { |
| 130 |
Modem *modem; |
| 131 |
Bearer *b; |
| 132 |
|
| 133 |
assert(manager); |
| 134 |
assert(path); |
| 135 |
|
| 136 |
HASHMAP_FOREACH(modem, manager->modems_by_path) { |
| 137 |
b = hashmap_get(modem->bearers_by_path, path); |
| 138 |
if (!b) |
| 139 |
continue; |
| 140 |
|
| 141 |
if (ret_bearer) |
| 142 |
*ret_bearer = b; |
| 143 |
if (ret_modem) |
| 144 |
*ret_modem = modem; |
| 145 |
return 0; |
| 146 |
} |
| 147 |
|
| 148 |
return -ENOENT; |
| 149 |
} |
| 150 |
|
| 151 |
Modem* modem_free(Modem *modem) { |
| 152 |
if (!modem) |
| 153 |
return NULL; |
| 154 |
|
| 155 |
hashmap_free(modem->bearers_by_name); |
| 156 |
hashmap_free(modem->bearers_by_path); |
| 157 |
|
| 158 |
if (modem->manager) |
| 159 |
hashmap_remove_value(modem->manager->modems_by_path, modem->path, modem); |
| 160 |
|
| 161 |
sd_bus_slot_unref(modem->slot_propertieschanged); |
| 162 |
sd_bus_slot_unref(modem->slot_statechanged); |
| 163 |
sd_bus_slot_unref(modem->slot_connect); |
| 164 |
|
| 165 |
free(modem->path); |
| 166 |
free(modem->manufacturer); |
| 167 |
free(modem->model); |
| 168 |
free(modem->port_name); |
| 169 |
|
| 170 |
return mfree(modem); |
| 171 |
} |
| 172 |
|
| 173 |
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( |
| 174 |
modems_hash_ops, |
| 175 |
char, |
| 176 |
string_hash_func, |
| 177 |
string_compare_func, |
| 178 |
Modem, |
| 179 |
modem_free); |
| 180 |
|
| 181 |
int modem_new(Manager *m, const char *path, Modem **ret) { |
| 182 |
_cleanup_(modem_freep) Modem *modem = NULL; |
| 183 |
_cleanup_free_ char *p = NULL; |
| 184 |
int r; |
| 185 |
|
| 186 |
assert(m); |
| 187 |
assert(path); |
| 188 |
|
| 189 |
if (hashmap_contains(m->modems_by_path, path)) |
| 190 |
return -EEXIST; |
| 191 |
|
| 192 |
p = strdup(path); |
| 193 |
if (!p) |
| 194 |
return -ENOMEM; |
| 195 |
|
| 196 |
modem = new(Modem, 1); |
| 197 |
if (!modem) |
| 198 |
return -ENOMEM; |
| 199 |
|
| 200 |
*modem = (Modem) { |
| 201 |
.manager = m, |
| 202 |
.path = TAKE_PTR(p), |
| 203 |
}; |
| 204 |
|
| 205 |
r = hashmap_ensure_put(&m->modems_by_path, &modems_hash_ops, modem->path, modem); |
| 206 |
if (r < 0) |
| 207 |
return r; |
| 208 |
|
| 209 |
if (ret) |
| 210 |
*ret = modem; |
| 211 |
|
| 212 |
TAKE_PTR(modem); |
| 213 |
return 0; |
| 214 |
} |
| 215 |
|
| 216 |
int modem_get_by_path(Manager *m, const char *path, Modem **ret) { |
| 217 |
Modem *modem; |
| 218 |
|
| 219 |
assert(m); |
| 220 |
assert(path); |
| 221 |
|
| 222 |
modem = hashmap_get(m->modems_by_path, path); |
| 223 |
if (!modem) |
| 224 |
return -ENOENT; |
| 225 |
|
| 226 |
if (ret) |
| 227 |
*ret = modem; |
| 228 |
|
| 229 |
return 0; |
| 230 |
} |
| 231 |
|
| 232 |
int link_get_modem(Link *link, Modem **ret) { |
| 233 |
Modem *modem; |
| 234 |
|
| 235 |
assert(link); |
| 236 |
assert(link->manager); |
| 237 |
assert(link->ifname); |
| 238 |
assert(ret); |
| 239 |
|
| 240 |
HASHMAP_FOREACH(modem, link->manager->modems_by_path) |
| 241 |
if (modem->port_name && streq(modem->port_name, link->ifname)) { |
| 242 |
*ret = modem; |
| 243 |
return 0; |
| 244 |
} |
| 245 |
|
| 246 |
return -ENOENT; |
| 247 |
} |
| 248 |
|
| 249 |
int link_get_bearer(Link *link, Bearer **ret) { |
| 250 |
Modem *modem; |
| 251 |
|
| 252 |
assert(link); |
| 253 |
assert(link->manager); |
| 254 |
assert(link->ifname); |
| 255 |
|
| 256 |
HASHMAP_FOREACH(modem, link->manager->modems_by_path) { |
| 257 |
Bearer *b; |
| 258 |
|
| 259 |
b = hashmap_get(modem->bearers_by_name, link->ifname); |
| 260 |
if (!b) |
| 261 |
continue; |
| 262 |
|
| 263 |
if (ret) |
| 264 |
*ret = b; |
| 265 |
return 0; |
| 266 |
} |
| 267 |
|
| 268 |
return -ENOENT; |
| 269 |
} |
| 270 |
|
| 271 |
int link_dhcp_enabled_by_bearer(Link *link, int family) { |
| 272 |
Bearer *b; |
| 273 |
int r; |
| 274 |
|
| 275 |
assert(link); |
| 276 |
assert(IN_SET(family, AF_INET, AF_INET6)); |
| 277 |
|
| 278 |
r = link_get_bearer(link, &b); |
| 279 |
if (r < 0) |
| 280 |
return r; |
| 281 |
|
| 282 |
if (!b->connected) |
| 283 |
return false; |
| 284 |
|
| 285 |
if (!FLAGS_SET(b->ip_type, family == AF_INET ? ADDRESS_FAMILY_IPV4 : ADDRESS_FAMILY_IPV6)) |
| 286 |
return false; |
| 287 |
|
| 288 |
return (family == AF_INET ? b->ip4_method : b->ip6_method) == MM_BEARER_IP_METHOD_DHCP; |
| 289 |
} |
| 290 |
|
| 291 |
static int bearer_address_handler( |
| 292 |
sd_netlink *rtnl, |
| 293 |
sd_netlink_message *m, |
| 294 |
Request *req, |
| 295 |
Link *link, |
| 296 |
Address *address) { |
| 297 |
|
| 298 |
int r; |
| 299 |
|
| 300 |
assert(link); |
| 301 |
|
| 302 |
r = address_configure_handler_internal(m, link, address); |
| 303 |
if (r <= 0) |
| 304 |
return r; |
| 305 |
|
| 306 |
if (link->bearer_messages == 0) { |
| 307 |
link->bearer_configured = true; |
| 308 |
link_check_ready(link); |
| 309 |
} |
| 310 |
|
| 311 |
return 0; |
| 312 |
} |
| 313 |
|
| 314 |
static int link_request_bearer_address( |
| 315 |
Link *link, |
| 316 |
int family, |
| 317 |
const union in_addr_union *addr, |
| 318 |
unsigned prefixlen) { |
| 319 |
|
| 320 |
_cleanup_(address_unrefp) Address *address = NULL; |
| 321 |
Address *existing; |
| 322 |
int r; |
| 323 |
|
| 324 |
assert(link); |
| 325 |
assert(IN_SET(family, AF_INET, AF_INET6)); |
| 326 |
assert(addr); |
| 327 |
|
| 328 |
if (!in_addr_is_set(family, addr)) |
| 329 |
return 0; |
| 330 |
|
| 331 |
r = address_new(&address); |
| 332 |
if (r < 0) |
| 333 |
return log_oom(); |
| 334 |
|
| 335 |
address->source = NETWORK_CONFIG_SOURCE_MODEM_MANAGER; |
| 336 |
address->family = family; |
| 337 |
address->in_addr = *addr; |
| 338 |
address->prefixlen = prefixlen; |
| 339 |
|
| 340 |
if (address_get(link, address, &existing) < 0) /* The address is new. */ |
| 341 |
link->bearer_configured = false; |
| 342 |
else |
| 343 |
address_unmark(existing); |
| 344 |
|
| 345 |
r = link_request_address(link, address, &link->bearer_messages, |
| 346 |
bearer_address_handler, /* ret = */ NULL); |
| 347 |
if (r < 0) |
| 348 |
return log_link_warning_errno(link, r, "Failed to request address provided by bearer: %m"); |
| 349 |
|
| 350 |
return 0; |
| 351 |
} |
| 352 |
|
| 353 |
static int bearer_route_handler( |
| 354 |
sd_netlink *rtnl, |
| 355 |
sd_netlink_message *m, |
| 356 |
Request *req, |
| 357 |
Link *link, |
| 358 |
Route *route) { |
| 359 |
|
| 360 |
int r; |
| 361 |
|
| 362 |
assert(link); |
| 363 |
|
| 364 |
r = route_configure_handler_internal(m, req, route); |
| 365 |
if (r <= 0) |
| 366 |
return r; |
| 367 |
|
| 368 |
if (link->bearer_messages == 0) { |
| 369 |
link->bearer_configured = true; |
| 370 |
link_check_ready(link); |
| 371 |
} |
| 372 |
|
| 373 |
return 0; |
| 374 |
} |
| 375 |
|
| 376 |
static int link_request_bearer_route( |
| 377 |
Link *link, |
| 378 |
int family, |
| 379 |
const union in_addr_union *gw, |
| 380 |
const union in_addr_union *prefsrc) { |
| 381 |
|
| 382 |
_cleanup_(route_unrefp) Route *route = NULL; |
| 383 |
Route *existing; |
| 384 |
int r; |
| 385 |
|
| 386 |
assert(link); |
| 387 |
assert(IN_SET(family, AF_INET, AF_INET6)); |
| 388 |
assert(gw); |
| 389 |
assert(prefsrc); |
| 390 |
|
| 391 |
if (!in_addr_is_set(family, gw)) |
| 392 |
return 0; |
| 393 |
|
| 394 |
if (link->network->mm_use_gateway == 0) |
| 395 |
return 0; |
| 396 |
|
| 397 |
r = route_new(&route); |
| 398 |
if (r < 0) |
| 399 |
return log_oom(); |
| 400 |
|
| 401 |
route->source = NETWORK_CONFIG_SOURCE_MODEM_MANAGER; |
| 402 |
route->family = family; |
| 403 |
route->nexthop.family = family; |
| 404 |
route->nexthop.gw = *gw; |
| 405 |
if (link->network->mm_route_metric_set) { |
| 406 |
route->priority = link->network->mm_route_metric; |
| 407 |
route->priority_set = true; |
| 408 |
} |
| 409 |
|
| 410 |
if (prefsrc) |
| 411 |
route->prefsrc = *prefsrc; |
| 412 |
|
| 413 |
if (route_get(link->manager, route, &existing) < 0) /* This is a new route. */ |
| 414 |
link->bearer_configured = false; |
| 415 |
else |
| 416 |
route_unmark(existing); |
| 417 |
|
| 418 |
r = link_request_route(link, route, &link->bearer_messages, bearer_route_handler); |
| 419 |
if (r < 0) |
| 420 |
return log_link_warning_errno(link, r, "Failed to request gateway provided by bearer: %m"); |
| 421 |
|
| 422 |
return 0; |
| 423 |
} |
| 424 |
|
| 425 |
static int link_apply_bearer_impl(Link *link, Bearer *b) { |
| 426 |
Address *address; |
| 427 |
Route *route; |
| 428 |
int r, ret = 0; |
| 429 |
|
| 430 |
assert(link); |
| 431 |
|
| 432 |
if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) |
| 433 |
return 0; |
| 434 |
|
| 435 |
/* First, mark bearer configs. */ |
| 436 |
SET_FOREACH(address, link->addresses) { |
| 437 |
if (address->source != NETWORK_CONFIG_SOURCE_MODEM_MANAGER) |
| 438 |
continue; |
| 439 |
|
| 440 |
address_mark(address); |
| 441 |
} |
| 442 |
|
| 443 |
SET_FOREACH(route, link->manager->routes) { |
| 444 |
if (route->source != NETWORK_CONFIG_SOURCE_MODEM_MANAGER) |
| 445 |
continue; |
| 446 |
|
| 447 |
route_mark(route); |
| 448 |
} |
| 449 |
|
| 450 |
if (b && FLAGS_SET(b->ip_type, ADDRESS_FAMILY_IPV4)) { |
| 451 |
if (b->connected && b->ip4_method == MM_BEARER_IP_METHOD_STATIC) { |
| 452 |
r = link_request_bearer_address(link, AF_INET, &b->ip4_address, b->ip4_prefixlen); |
| 453 |
if (r < 0) |
| 454 |
return r; |
| 455 |
|
| 456 |
r = link_request_bearer_route(link, AF_INET, &b->ip4_gateway, &b->ip4_address); |
| 457 |
if (r < 0) |
| 458 |
return r; |
| 459 |
} |
| 460 |
|
| 461 |
if (b->connected && b->ip4_method == MM_BEARER_IP_METHOD_DHCP) { |
| 462 |
if (!link_dhcp4_enabled(link)) |
| 463 |
log_link_notice(link, "The WWAN connection requested DHCPv4 client, but it is disabled."); |
| 464 |
|
| 465 |
r = dhcp4_start(link); |
| 466 |
if (r < 0) |
| 467 |
return log_link_warning_errno(link, r, "Failed to start DHCPv4 client: %m"); |
| 468 |
} else { |
| 469 |
r = sd_dhcp_client_stop(link->dhcp_client); |
| 470 |
if (r < 0) |
| 471 |
ret = log_link_warning_errno(link, r, "Could not stop DHCPv4 client: %m"); |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
if (b && FLAGS_SET(b->ip_type, ADDRESS_FAMILY_IPV6)) { |
| 476 |
if (b->connected && b->ip6_method == MM_BEARER_IP_METHOD_STATIC) { |
| 477 |
r = link_request_bearer_address(link, AF_INET6, &b->ip6_address, b->ip6_prefixlen); |
| 478 |
if (r < 0) |
| 479 |
return r; |
| 480 |
|
| 481 |
r = link_request_bearer_route(link, AF_INET6, &b->ip6_gateway, &b->ip6_address); |
| 482 |
if (r < 0) |
| 483 |
return r; |
| 484 |
} |
| 485 |
|
| 486 |
if (b->connected && b->ip6_method == MM_BEARER_IP_METHOD_DHCP) { |
| 487 |
if (!link_ndisc_enabled(link) && !link_dhcp6_enabled(link)) |
| 488 |
log_link_notice(link, |
| 489 |
"The WWAN connection requested IPv6 dynamic address configuration," |
| 490 |
"but both IPv6 Router Discovery and DHCPv6 client are disabled."); |
| 491 |
|
| 492 |
r = ndisc_start(link); |
| 493 |
if (r < 0) |
| 494 |
return log_link_warning_errno(link, r, "Failed to start IPv6 Router Discovery: %m"); |
| 495 |
|
| 496 |
r = dhcp6_start(link); |
| 497 |
if (r < 0) |
| 498 |
return log_link_warning_errno(link, r, "Failed to start DHCPv6 client: %m"); |
| 499 |
} else { |
| 500 |
r = sd_dhcp6_client_stop(link->dhcp6_client); |
| 501 |
if (r < 0) |
| 502 |
ret = log_link_warning_errno(link, r, "Could not stop DHCPv6 client: %m"); |
| 503 |
|
| 504 |
r = sd_ndisc_stop(link->ndisc); |
| 505 |
if (r < 0) |
| 506 |
ret = log_link_warning_errno(link, r, "Could not stop IPv6 Router Discovery: %m"); |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
/* Finally, remove all marked configs. */ |
| 511 |
SET_FOREACH(address, link->addresses) { |
| 512 |
if (address->source != NETWORK_CONFIG_SOURCE_MODEM_MANAGER) |
| 513 |
continue; |
| 514 |
|
| 515 |
if (!address_is_marked(address)) |
| 516 |
continue; |
| 517 |
|
| 518 |
r = address_remove(address, link); |
| 519 |
if (r < 0) |
| 520 |
ret = r; |
| 521 |
} |
| 522 |
|
| 523 |
SET_FOREACH(route, link->manager->routes) { |
| 524 |
if (route->source != NETWORK_CONFIG_SOURCE_MODEM_MANAGER) |
| 525 |
continue; |
| 526 |
|
| 527 |
if (!route_is_marked(route)) |
| 528 |
continue; |
| 529 |
|
| 530 |
r = route_remove(route, link->manager); |
| 531 |
if (r < 0) |
| 532 |
ret = r; |
| 533 |
} |
| 534 |
|
| 535 |
if (ret < 0) |
| 536 |
return ret; |
| 537 |
|
| 538 |
if (link->bearer_messages == 0) |
| 539 |
link->bearer_configured = true; |
| 540 |
|
| 541 |
if (!link->bearer_configured) |
| 542 |
link_set_state(link, LINK_STATE_CONFIGURING); |
| 543 |
|
| 544 |
link_check_ready(link); |
| 545 |
|
| 546 |
return 0; |
| 547 |
} |
| 548 |
|
| 549 |
int link_apply_bearer(Link *link) { |
| 550 |
Bearer *b = NULL; |
| 551 |
int r; |
| 552 |
|
| 553 |
assert(link); |
| 554 |
|
| 555 |
(void) link_get_bearer(link, &b); |
| 556 |
|
| 557 |
r = link_apply_bearer_impl(link, b); |
| 558 |
if (r < 0) |
| 559 |
link_enter_failed(link); |
| 560 |
|
| 561 |
return r; |
| 562 |
} |
| 563 |
|
| 564 |
int bearer_update_link(Bearer *b) { |
| 565 |
Link *link; |
| 566 |
int r; |
| 567 |
|
| 568 |
assert(b); |
| 569 |
assert(b->modem); |
| 570 |
assert(b->modem->manager); |
| 571 |
|
| 572 |
if (!b->name) |
| 573 |
return 0; |
| 574 |
|
| 575 |
if (link_get_by_name(b->modem->manager, b->name, &link) < 0) |
| 576 |
return 0; |
| 577 |
|
| 578 |
r = link_apply_bearer_impl(link, b); |
| 579 |
if (r < 0) |
| 580 |
link_enter_failed(link); |
| 581 |
|
| 582 |
/* |
| 583 |
* Need to bring up the interface after the modem has connected. |
| 584 |
* This is because ModemManger does the following while connecting: |
| 585 |
* <msg> [1755871777.322239] [modem2] state changed (registered -> connecting) |
| 586 |
* <dbg> [1755871777.325012] [modem2/bearer5] launching connection with QMI port (cdc-wdm0) and data port (wwan0) (multiplex none) |
| 587 |
* <dbg> [1755871777.327665] [cdc-wdm0/qmi] bringing down data interface 'wwan0' |
| 588 |
* <dbg> [1755871777.330108] [modem2/wwan0/net] interface index: 9 |
| 589 |
* <dbg> [1755871777.335265] [cdc-wdm0/qmi] deleting all links in data interface 'wwan0' |
| 590 |
*/ |
| 591 |
|
| 592 |
r = link_request_to_bring_up_or_down(link, b->connected); |
| 593 |
if (r < 0) |
| 594 |
link_enter_failed(link); |
| 595 |
|
| 596 |
return 0; |
| 597 |
} |
| 598 |
|
| 599 |
void bearer_drop(Bearer *b) { |
| 600 |
assert(b); |
| 601 |
|
| 602 |
b->connected = false; |
| 603 |
b->apn = mfree(b->apn); |
| 604 |
|
| 605 |
(void) bearer_update_link(b); |
| 606 |
|
| 607 |
bearer_free(b); |
| 608 |
} |
| 609 |
|
| 610 |
int config_parse_mm_route_metric( |
| 611 |
const char *unit, |
| 612 |
const char *filename, |
| 613 |
unsigned line, |
| 614 |
const char *section, |
| 615 |
unsigned section_line, |
| 616 |
const char *lvalue, |
| 617 |
int ltype, |
| 618 |
const char *rvalue, |
| 619 |
void *data, |
| 620 |
void *userdata) { |
| 621 |
|
| 622 |
Network *network = ASSERT_PTR(userdata); |
| 623 |
int r; |
| 624 |
|
| 625 |
assert(filename); |
| 626 |
assert(lvalue); |
| 627 |
assert(rvalue); |
| 628 |
|
| 629 |
if (isempty(rvalue)) { |
| 630 |
network->mm_route_metric_set = false; |
| 631 |
return 0; |
| 632 |
} |
| 633 |
|
| 634 |
r = safe_atou32(rvalue, &network->mm_route_metric); |
| 635 |
if (r < 0) |
| 636 |
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); |
| 637 |
|
| 638 |
network->mm_route_metric_set = true; |
| 639 |
return 0; |
| 640 |
} |
| 641 |
|
| 642 |
int config_parse_mm_allowed_auth( |
| 643 |
const char *unit, |
| 644 |
const char *filename, |
| 645 |
unsigned line, |
| 646 |
const char *section, |
| 647 |
unsigned section_line, |
| 648 |
const char *lvalue, |
| 649 |
int ltype, |
| 650 |
const char *rvalue, |
| 651 |
void *data, |
| 652 |
void *userdata) { |
| 653 |
|
| 654 |
static const struct { |
| 655 |
MMBearerAllowedAuth auth; |
| 656 |
const char *str; |
| 657 |
} allowed_auth_map[] = { |
| 658 |
{ MM_BEARER_ALLOWED_AUTH_NONE, "none" }, |
| 659 |
{ MM_BEARER_ALLOWED_AUTH_PAP, "pap" }, |
| 660 |
{ MM_BEARER_ALLOWED_AUTH_CHAP, "chap" }, |
| 661 |
{ MM_BEARER_ALLOWED_AUTH_MSCHAP, "mschap" }, |
| 662 |
{ MM_BEARER_ALLOWED_AUTH_MSCHAPV2, "mschapv2" }, |
| 663 |
{ MM_BEARER_ALLOWED_AUTH_EAP, "eap" }, |
| 664 |
}; |
| 665 |
MMBearerAllowedAuth *allowed_auth = ASSERT_PTR(data); |
| 666 |
int r; |
| 667 |
|
| 668 |
assert(filename); |
| 669 |
assert(lvalue); |
| 670 |
assert(rvalue); |
| 671 |
|
| 672 |
if (isempty(rvalue)) { |
| 673 |
*allowed_auth = MM_BEARER_ALLOWED_AUTH_UNKNOWN; |
| 674 |
return 0; |
| 675 |
} |
| 676 |
|
| 677 |
for (const char *p = rvalue;;) { |
| 678 |
_cleanup_free_ char *auth = NULL; |
| 679 |
|
| 680 |
r = extract_first_word(&p, &auth, /* separators */ NULL, /* flags */ 0); |
| 681 |
if (r < 0) |
| 682 |
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); |
| 683 |
if (r == 0) |
| 684 |
return 0; |
| 685 |
|
| 686 |
bool found = false; |
| 687 |
FOREACH_ELEMENT(i, allowed_auth_map) |
| 688 |
if (streq(auth, i->str)) { |
| 689 |
*allowed_auth |= i->auth; |
| 690 |
found = true; |
| 691 |
break; |
| 692 |
} |
| 693 |
|
| 694 |
if (!found) |
| 695 |
log_syntax(unit, LOG_WARNING, filename, line, -EINVAL, |
| 696 |
"Unknown auth value '%s', ignoring", auth); |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
int config_parse_mm_ip_family( |
| 701 |
const char *unit, |
| 702 |
const char *filename, |
| 703 |
unsigned line, |
| 704 |
const char *section, |
| 705 |
unsigned section_line, |
| 706 |
const char *lvalue, |
| 707 |
int ltype, |
| 708 |
const char *rvalue, |
| 709 |
void *data, |
| 710 |
void *userdata) { |
| 711 |
|
| 712 |
static const struct { |
| 713 |
MMBearerIpFamily family; |
| 714 |
const char *str; |
| 715 |
} ip_family_map[] = { |
| 716 |
{ MM_BEARER_IP_FAMILY_IPV4, "ipv4" }, |
| 717 |
{ MM_BEARER_IP_FAMILY_IPV6, "ipv6" }, |
| 718 |
{ MM_BEARER_IP_FAMILY_IPV4V6, "both" }, |
| 719 |
{ MM_BEARER_IP_FAMILY_ANY, "any" }, |
| 720 |
}; |
| 721 |
MMBearerIpFamily *ip_family = ASSERT_PTR(data); |
| 722 |
|
| 723 |
assert(filename); |
| 724 |
assert(lvalue); |
| 725 |
assert(rvalue); |
| 726 |
|
| 727 |
if (isempty(rvalue)) { |
| 728 |
*ip_family = MM_BEARER_IP_FAMILY_NONE; |
| 729 |
return 0; |
| 730 |
} |
| 731 |
|
| 732 |
FOREACH_ELEMENT(i, ip_family_map) |
| 733 |
if (streq(rvalue, i->str)) { |
| 734 |
*ip_family = i->family; |
| 735 |
return 0; |
| 736 |
} |
| 737 |
|
| 738 |
return log_syntax_parse_error(unit, filename, line, -EINVAL, lvalue, rvalue); |
| 739 |
} |