@@ -282,7 +282,7 @@ def add_server(args):
282282 )
283283 zone = f"{ instance } vpn"
284284 firewall .add_trusted_zone (e_uci , zone , link = f"network/{ instance } " )
285- firewall .add_device_to_zone (e_uci , instance , zone )
285+ firewall .add_interface_to_zone (e_uci , instance , zone )
286286
287287 return {"result" : "success" }
288288
@@ -426,6 +426,7 @@ def add_peer(args):
426426 e_uci .set ('network' , peer_section , 'public_key' , public_key )
427427 e_uci .set ('network' , peer_section , 'private_key' , private_key )
428428 e_uci .set ('network' , peer_section , 'persistent_keepalive' , 25 )
429+ e_uci .set ('network' , peer_section , 'route_allowed_ips' , True )
429430 e_uci .set ('network' , peer_section , 'ns_link' , f'network/{ args ["instance" ]} ' )
430431 e_uci .save ('network' )
431432
@@ -504,7 +505,9 @@ def __generate_peer_config(server_id, peer_id):
504505 if e_uci .get ('network' , peer_id , 'ns_route_all_traffic' , dtype = bool , default = False ):
505506 config += "AllowedIPs = 0.0.0.0/0, ::/0\n "
506507 else :
507- config += f"AllowedIPs = { ',' .join (e_uci .get ('network' , peer_id , 'allowed_ips' , list = True , dtype = str ))} \n "
508+ addresses = list (e_uci .get ('network' , peer_id , 'ns_local_routes' , list = True , dtype = str , default = []))
509+ addresses .append (e_uci .get ('network' , server_id , 'ns_network' , dtype = str ))
510+ config += f"AllowedIPs = { ',' .join (addresses )} \n "
508511 config += f"Endpoint = { e_uci .get ('network' , server_id , 'ns_public_endpoint' )} :{ e_uci .get ('network' , server_id , 'listen_port' )} \n "
509512 config += f"PersistentKeepalive = { e_uci .get ('network' , peer_id , 'persistent_keepalive' , default = '25' )} \n "
510513
@@ -566,9 +569,13 @@ def import_configuration(args):
566569 e_uci .set ('network' , peer_instance , 'allowed_ips' , [ip .strip () for ip in config_parser ["Peer" ]["AllowedIPs" ].split (',' )])
567570 e_uci .set ('network' , peer_instance , 'endpoint_host' , config_parser ["Peer" ]["Endpoint" ].split (':' )[0 ])
568571 e_uci .set ('network' , peer_instance , 'endpoint_port' , config_parser ["Peer" ]["Endpoint" ].split (':' )[1 ])
572+ e_uci .set ('network' , peer_instance , 'route_allowed_ips' , True )
569573 e_uci .set ('network' , peer_instance , 'persistent_keepalive' , config_parser ["Peer" ].get ("PersistentKeepalive" , "25" ))
570574 e_uci .set ('network' , peer_instance , 'ns_link' , f'network/{ defaults ["instance" ]} ' )
571575 e_uci .save ('network' )
576+ zone = f"{ defaults ['instance' ]} vpn"
577+ firewall .add_trusted_zone (e_uci , zone , link = f"network/{ defaults ['instance' ]} " )
578+ firewall .add_interface_to_zone (e_uci , defaults ['instance' ], zone )
572579 except Exception :
573580 return utils .validation_error ("config" , "invalid_file_format" )
574581
@@ -665,11 +672,15 @@ def add_tunnel(args):
665672 e_uci .set ('network' , peer_instance , 'reserved_ip' , args ['reserved_ip' ])
666673 e_uci .set ('network' , peer_instance , 'endpoint_host' , args ['endpoint' ])
667674 e_uci .set ('network' , peer_instance , 'endpoint_port' , args ['udp_port' ])
675+ e_uci .set ("network" , peer_instance , "route_allowed_ips" , True )
668676 e_uci .set ('network' , peer_instance , 'persistent_keepalive' , args .get ('persistent_keepalive' , '25' ))
669677 e_uci .set ('network' , peer_instance , 'ns_link' , f'network/{ defaults ["instance" ]} ' )
670678 if 'dns' in args :
671679 e_uci .set ('network' , defaults ['instance' ], 'dns' , args ['dns' ])
672680 e_uci .save ('network' )
681+ zone = f"{ defaults ['instance' ]} vpn"
682+ firewall .add_trusted_zone (e_uci , zone , link = f"network/{ defaults ['instance' ]} " )
683+ firewall .add_interface_to_zone (e_uci , defaults ["instance" ], zone )
673684
674685 return {"result" : "success" }
675686
@@ -733,6 +744,7 @@ def delete_tunnel(args):
733744 if e_uci .get ('network' , entry , 'ns_link' , dtype = str , default = '' ) == f'network/{ args ["id" ]} ' :
734745 e_uci .delete ('network' , entry )
735746 e_uci .save ('network' )
747+ firewall .delete_linked_sections (e_uci , f"network/{ args ['id' ]} " )
736748
737749 return {"result" : "success" }
738750
0 commit comments