Browse Source

Fix session id and duplicate session

McKay1717 6 years ago
parent
commit
97bfa01b98
3 changed files with 5 additions and 8 deletions
  1. 3 6
      generate_config_bird.py
  2. 1 1
      templates/bird_v4.j2
  3. 1 1
      templates/bird_v6.j2

+ 3 - 6
generate_config_bird.py

@@ -65,7 +65,7 @@ def parse_peers(peer_file, version):
 
             env = Environment(loader=FileSystemLoader('./'))
 
-            if version == 6 and 'neighbor_ipv6' in locals():
+            if version == 6 and 'neighbor_ipv6' in locals() and type(ipaddr.IPAddress(peer_ip)) is ipaddr.IPv6Address:
                 #Generate IPV6
                 tpl = env.get_template('templates/bird_v6.j2')
 
@@ -74,10 +74,8 @@ def parse_peers(peer_file, version):
                            import_as=peerings[asn]['import'],
                            neighbor_ipv6=neighbor_ipv6, ix_name=
                            ixp, limit_ipv6=limit_ipv6, session_num=session)
-                if session == 1:
-                    break
             else:
-                if 'neighbor_ipv4' in locals():
+                if 'neighbor_ipv4' in locals() and type(ipaddr.IPAddress(peer_ip)) is ipaddr.IPv4Address:
                     #Generate IPV4
                     tpl = env.get_template('templates/bird_v4.j2')
 
@@ -86,8 +84,7 @@ def parse_peers(peer_file, version):
                                import_as=peerings[asn]['import'], neighbor_ipv4=
                                neighbor_ipv4,ix_name=ixp,
                                limit_ipv4=limit_ipv4, session_num=session)
-                    if session == 1:
-                        break
+
 
 #Basicly check arg
 if len(sys.argv) == 2:

+ 1 - 1
templates/bird_v4.j2

@@ -1,4 +1,4 @@
-protocol bgp {{ ix_name }}_{{ neighbor_as }}_{{ session_num }} from tpl_{{ ix_name }}_peers {
+protocol bgp {{ ix_name }}_{{ neighbor_as }}{%- if session_num > 1 %}_{{ session_num }}{%- endif %} from tpl_{{ ix_name }}_peers {
     neighbor {{ neighbor_ipv4 }} as {{ neighbor_as }};
     description "{{ ix_name }} / {{ description }}";
     {%- if limit_ipv4 %}

+ 1 - 1
templates/bird_v6.j2

@@ -1,4 +1,4 @@
-protocol bgp {{ ix_name }}_{{ neighbor_as }}_{{ session_num }}  from tpl_{{ ix_name }}_peers {
+protocol bgp {{ ix_name }}_{{ neighbor_as }}{%- if session_num > 1 %}_{{ session_num }}{%- endif %}  from tpl_{{ ix_name }}_peers {
     neighbor {{ neighbor_ipv6 }} as {{ neighbor_as }};
     description "{{ ix_name }} / {{ description }}";
     {%- if limit_ipv6 %}