ccie blog

BGP automatic-tag & as-path tag

When redistributing BGP into an IGP we lose all our BGP attributes.  In the diagram below, R2 redistributes BGP into OSPF.  R3 then redistributes OSPF into BGP.  When R4 finally receives the 100.100.100.0/24 prefix, it will appear as though AS 20 was the originating AS.  It will also appear as though the origin code of the route is a ? (redistributed) because AS20 injected this route from OSPF into BGP.  Obviously this is all wrong, as AS10 originated the prefix, and he did so with a BGP network statement; it wasn’t redistributed.  In this lab we’re going to use the automatic-tag and as-path tag commands so that R3 will advertise the correct BGP AS_PATH & ORIGIN information to R4.

I have provided the BGP & OSPF configuration on each device (currently).

R1#sh run | s router
router bgp 10
 no synchronization
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 network 14.14.14.0 mask 255.255.255.252
 network 100.100.100.0 mask 255.255.255.0
 neighbor 14.14.14.2 remote-as 20
 no auto-summary
R2#sh run | s router
router ospf 1
 log-adjacency-changes
 redistribute bgp 20 subnets
 passive-interface FastEthernet0/0
 network 12.12.12.0 0.0.0.3 area 0
 network 14.14.14.0 0.0.0.3 area 0
router bgp 20
 no synchronization
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 redistribute ospf 1 match internal external 1 external 2
 neighbor 14.14.14.1 remote-as 10
 no auto-summary
R3#sh run | s router
router ospf 1
 log-adjacency-changes
 redistribute bgp 20 subnets
 passive-interface FastEthernet1/0
 network 12.12.12.0 0.0.0.3 area 0
 network 26.26.26.0 0.0.0.3 area 0
router bgp 20
 no synchronization
 bgp router-id 3.3.3.3
 bgp log-neighbor-changes
 redistribute ospf 1 match internal external 1 external 2
 neighbor 26.26.26.2 remote-as 30
 no auto-summary
R4#sh run | s router
router bgp 30
 no synchronization
 bgp router-id 4.4.4.4
 bgp log-neighbor-changes
 neighbor 26.26.26.1 remote-as 20
 no auto-summary

Let’s start by configuring the as-path tag.  By default, when you redistribute BGP into an IGP, IOS will set the Tag field with the AS_PATH attribute.  We can see this on R2 below:

R2#sh ip route 100.100.100.0
Routing entry for 100.100.100.0/24
  Known via "bgp 20", distance 20, metric 0
  Tag 10, type external
  Redistributing via ospf 1
  Advertised by ospf 1 subnets
  Last update from 14.14.14.1 00:49:31 ago
  Routing Descriptor Blocks:
  * 14.14.14.1, from 14.14.14.1, 00:49:31 ago
      Route metric is 0, traffic share count is 1
      AS Hops 1
      Route tag 10

This value is propagated to R3.  All we need to do, is bring the value in the Tag field back out when we advertise prefixes to R4.  Let’s do that now.  I’m also going to include a before and after shot of the BGP table on R4 for the 100.100.100.0/24 prefix.  You will see that the AS_PATH gets adjusted.

//Before
R4#sh ip bgp 100.100.100.0
BGP routing table entry for 100.100.100.0/24, version 17
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
  Not advertised to any peer
  20
    26.26.26.1 from 26.26.26.1 (3.3.3.3)
      Origin incomplete, metric 1, localpref 100, valid, external, best
R3#conf t
R3(config)#route-map GET_TAG permit 10
R3(config-route-map)#set as-path ?
  prepend  Prepend to the as-path
  tag      Set the tag as an AS-path attribute

R3(config-route-map)#set as-path tag

R3(config-route-map)#router bgp 20
R3(config-router)#redistribute ospf 1 match internal external 1 external 2 route-map GET_TAG
//After
R4#sh ip bgp 100.100.100.0
BGP routing table entry for 100.100.100.0/24, version 16
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
  Not advertised to any peer
  20 10
    26.26.26.1 from 26.26.26.1 (3.3.3.3)
      Origin incomplete, metric 1, localpref 100, valid, external, best

Cool, so we’ve fixed the AS_PATH problem.  However, our Origin code still says “incomplete”.  The way we fix this is by setting the automatic-tag when the route was originally redistributed from BGP into OSPF on R2.

R2(config)#router bgp 20
R2(config-router)#table-map set_tag
R2(config-router)#
R2(config-router)#route-map set_tag permit 10
R2(config-route-map)#match as-path 1
R2(config-route-map)#set automatic-tag
R2(config-route-map)#exit
R2(config)#ip as-path access-list 1 permit .*
R2(config)#end
R2#clear ip bgp *

If we check R4, we cab now see that the origin code is now correct.

R4#sh ip bgp  100.100.100.0
BGP routing table entry for 100.100.100.0/24, version 19
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
  Not advertised to any peer
  20 10
    26.26.26.1 from 26.26.26.1 (3.3.3.3)
      Origin IGP, metric 1, localpref 100, valid, external, best

7 Comments

google seoJanuary 5th, 2013 at 10:49 am

Thanks in advance and good luck, ccieblog.co.uk ! 🙂

SofianeFebruary 12th, 2013 at 12:43 pm

Hello,

Good article

I have another result in my lab , see below:
R4#sh ip bgp 100.100.100.0
BGP routing table entry for 100.100.100.0/24, version 8
Paths: (1 available, best #1, table default)
Not advertised to any peer
Refresh Epoch 1
20 3489660938
26.26.26.1 from 26.26.26.1 (3.3.3.3)
Origin IGP, metric 1, localpref 100, valid, external, best

You have an error in the R1 & R2 BGP configuration , the ip address I think,

Best.

StephenGarbettFebruary 15th, 2013 at 10:31 am

Hey, thanks for your feedback. I adjusted the IP address configuration to make it work with the diagram. Thanks for that, good spot!

In your config, it looks like you have learned the 100.100.100.0 route via an IGP from R3 rather than from eBGP. Make sure you have a passive interface on R3 towards R4 and you should hopefully be able to resolve the problem from there.

Regards,
Stephen

SteveJuly 24th, 2014 at 10:03 pm

If anyone views Ithis post: s it possible to remove any of the ASN’s during the Redistribution Process?

StephenGarbettAugust 1st, 2014 at 10:14 am

Hi,

Yes there are a few methods. If the AS is a private AS, you can just use the #neighbor x.x.x.x remove-private-as command. Alternatively you can just override the BGP AS number before sending the update out. So in the diagram on this post, if you wanted 100.100.100.0/24 to appear as though it originated in AS20 when it gets to R4. You can use the as-override command on R3 towards R4. I talk about these topics in the links below:
http://ccieblog.co.uk/bgp/bgp-as-override-vs-allow-as-in
http://ccieblog.co.uk/bgp/bgp-remove-private-as

There is no actual method of just stripping the BGP AS number from the update though.

Con7eApril 12th, 2016 at 1:40 pm

For anyone coming here from Google (like I did), the reason you will obtain a result different from the author’s is because you, unlike him, did not remove the previously configured route-map “GET_TAG”. If you leave this config your AS_PATH will be like the one in Sofiane’s output. If you remove this config before enabling the “set automatic-tag” then you will see the correct result.

Unfortunately the author did not mention to do this so I spent a good deal of time troubleshooting the issue 😛

StephenGarbettMay 19th, 2016 at 12:32 pm

Nice spot, thank you.

Leave a comment

Your comment