3

I'm looking for a particular AS-PATH regex that match the following case: "accept ONLY neighbour and it's direct peers".

i.e., my neighbour is AS 20, and has 101, 102 as direct peers.

the as-path "20+ .?" correctly matches the following:

20
20 101
20 102
20 20 20 101

but it does not work if AS 101 is doing AS-prepending (i.e. 20 101 101 101).

Is there a way to achieve that? (if I remember well, in Cisco IOS I can use the \1)

thanks stefano

3
  • (please note that AS101 and AS102 can be whatever, and I won't know it) – Stefano Sasso Mar 23 '15 at 16:10
  • Please integrate this specification within your OQ. – dan May 29 '15 at 14:12
  • Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer. – Ron Maupin Aug 11 '17 at 14:39
2

This is not possible on JunOS as the AS-Path regular expressions do not support back references (Inserting (part of) a matched expression back into the regular expression itself).

0
1

So, correct me if I'm wrong in interpreting your question, or if it doesn't make sense - I'll be happy to update my answer.

You want to match on, your neighbor (AS20) whether AS20 does prepending or not, and ANY neighbor of AS20. Your regex would need to be:

20+ .*  ## Path of any length that begins with 1 or more occurrences of AS20.

To break it down:

20+     ## One or more occurrences of AS20.
.*      ## Any length AS_Path, of any AS number.

Here's what you had, you were close:

20+     ## One or more occurrences of AS20.
.?      ## Zero or one occurrences of any AS number (after the first statement).  

The .? was why you couldn't see if AS20's neighboring AS's were pre-pending.

3
  • Thanks for your reply, what I want to achieve is match AS20 whether AS20 does prepending or not, and ANY neighbor of AS, whether they do prepending or not. So, 20+ .* would also match 20 20 10 10 30 40 50, but I want to match only 20 20 10 10 (to be clear, only two AS number in the path) thanks. – Stefano Sasso Mar 24 '15 at 9:48
  • Unfortunately, there really isn't a way to say "Only accept my neighbor, and their directly connected neighbor", without specifying some other AS number that might be connected (you can put a list in the regex). You MIGHT be able to write this functionality into an event script, but I'm not sure if there is a way to essentially break how BGP receives routes in favor of your script - to be honest, I kind of doubt there is. – Jordan Head Mar 24 '15 at 17:28
  • Actually, what you COULD do if you went with the event script. You could accept whatever prefixes in BGP from AS 20 (regardless of 20, 10, 10, or 20, 10, 10, 50 - etc.) The script could look at the AS_Paths from each prefix and add them to a policy to not accept, or have some other policy operate on them to do what you needed. But again, they would be in your routing table at some point, not sure how many prefixes we're talking about - but it could result in a lot of CPU churn, or blackholed traffic unless you're EXTREMELY careful with the logic. – Jordan Head Mar 24 '15 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.