Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Mwan objects #61

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/nethsec/mwan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,12 +602,20 @@ def edit_rule(e_uci: EUci, name: str, policy: str, label: str, protocol: str = N
e_uci.set('mwan3', name, 'src_port', source_port.replace('-', ':'))
if source_address is not None:
e_uci.set('mwan3', name, 'src_ip', source_address)
else:
e_uci.delete('mwan3', name, 'src_ip')
if destination_address is not None:
e_uci.set('mwan3', name, 'dest_ip', destination_address)
else:
e_uci.delete('mwan3', name, 'dest_ip')
if ns_src is not None:
e_uci.set('mwan3', name, 'ns_src', ns_src)
else:
e_uci.delete('mwan3', name, 'ns_src')
if ns_dst is not None:
e_uci.set('mwan3', name, 'ns_dst', ns_dst)
else:
e_uci.delete('mwan3', name, 'ns_dst')
update_rules(e_uci) # update rules with objects and save mwan3 config
return f'mwan3.{name}'

Expand Down
21 changes: 12 additions & 9 deletions src/nethsec/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,27 +776,30 @@ def list_dns_records(uci, expand=False, used_info=False):
records.append(record)
return records

def list_objects(uci, include_domain_sets=True, singleton_only=False, expand=False):
def list_objects(uci, include_domain_sets=True, include_host_sets=True, singleton_only=False, expand=False):
"""
Get objects from objects, dhcp, and users config

Args:
uci: EUci pointer
include_domain_sets: include domain sets in the list
include_host_sets: include host sets in the list
expand: expand the list with all IP addresses of the object

Returns:
a list of all objects
"""
hsets = []
dsets = []
for h in list_host_sets(uci, True):
if singleton_only and not h['singleton']:
continue
h['id'] = f"objects/{h['id']}"
h['type'] = 'host_set'
if not expand:
del[h['ipaddr']]
hsets.append(h)
if include_host_sets:
for h in list_host_sets(uci, True):
if singleton_only and not h['singleton']:
continue
h['id'] = f"objects/{h['id']}"
h['type'] = 'host_set'
if not expand:
del[h['ipaddr']]
hsets.append(h)

if include_domain_sets:
for d in list_domain_sets(uci, True):
Expand Down
Loading