|
1 |
| -# Copyright 2023-2024 VyOS maintainers and contributors <maintainers@vyos.io> |
| 1 | +# Copyright 2023-2025 VyOS maintainers and contributors <maintainers@vyos.io> |
2 | 2 | #
|
3 | 3 | # This library is free software; you can redistribute it and/or
|
4 | 4 | # modify it under the terms of the GNU Lesser General Public
|
@@ -329,6 +329,32 @@ def kea_get_leases(inet):
|
329 | 329 |
|
330 | 330 | return leases['arguments']['leases']
|
331 | 331 |
|
| 332 | +def kea_add_lease(inet, ip_address, host_name=None, mac_address=None, iaid=None, duid=None, subnet_id=None): |
| 333 | + args = {'ip-address': ip_address} |
| 334 | + |
| 335 | + if host_name: |
| 336 | + args['hostname'] = host_name |
| 337 | + |
| 338 | + if subnet_id: |
| 339 | + args['subnet-id'] = subnet_id |
| 340 | + |
| 341 | + # IPv4 requires MAC address, IPv6 requires either MAC address or DUID |
| 342 | + if mac_address: |
| 343 | + args['hw-address'] = mac_address |
| 344 | + if duid: |
| 345 | + args['duid'] = duid |
| 346 | + |
| 347 | + # IPv6 requires IAID |
| 348 | + if inet == '6' and iaid: |
| 349 | + args['iaid'] = iaid |
| 350 | + |
| 351 | + result = _ctrl_socket_command(inet, f'lease{inet}-add', args) |
| 352 | + |
| 353 | + if result and 'result' in result: |
| 354 | + return result['result'] == 0 |
| 355 | + |
| 356 | + return False |
| 357 | + |
332 | 358 | def kea_delete_lease(inet, ip_address):
|
333 | 359 | args = {'ip-address': ip_address}
|
334 | 360 |
|
@@ -362,3 +388,26 @@ def kea_get_pool_from_subnet_id(config, inet, subnet_id):
|
362 | 388 | return network['name']
|
363 | 389 |
|
364 | 390 | return None
|
| 391 | + |
| 392 | +def kea_get_domain_from_subnet_id(config, inet, subnet_id): |
| 393 | + shared_networks = dict_search_args(config, 'arguments', f'Dhcp{inet}', 'shared-networks') |
| 394 | + |
| 395 | + if not shared_networks: |
| 396 | + return None |
| 397 | + |
| 398 | + for network in shared_networks: |
| 399 | + if f'subnet{inet}' not in network: |
| 400 | + continue |
| 401 | + |
| 402 | + for subnet in network[f'subnet{inet}']: |
| 403 | + if 'id' in subnet and int(subnet['id']) == int(subnet_id): |
| 404 | + for option in subnet['option-data']: |
| 405 | + if option['name'] == 'domain-name': |
| 406 | + return option['data'] |
| 407 | + |
| 408 | + # domain-name is not found in subnet, fallback to shared-network pool option |
| 409 | + for option in network['option-data']: |
| 410 | + if option['name'] == 'domain-name': |
| 411 | + return option['data'] |
| 412 | + |
| 413 | + return None |
0 commit comments