The policy should work. I tested in my lab.
R1---ebgp----R2-----ibgp----R3
R1 is originating default route to R2 and it is advertising to R3. policy is applied on R2. Outputs with and without next-hop self policy on R2 is given below:
Before:
+++++++++
root@R3# run show route protocol bgp hidden
inet.0: 14 destinations, 14 routes (14 active, 0 holddown, 0 hidden)
inet6.0: 19 destinations, 23 routes (18 active, 0 holddown, 1 hidden)
+ = Active Route, - = Last Active, * = Both
::/0 [BGP/170] 00:00:09, localpref 100, from 2001:db8:2::15
AS path: 100 I, validation-state: unverified
Unusable
[edit]
root@R3# run show route protocol bgp hidden extensive
inet.0: 14 destinations, 14 routes (14 active, 0 holddown, 0 hidden)
inet6.0: 19 destinations, 23 routes (18 active, 0 holddown, 1 hidden)
::/0 (1 entry, 0 announced)
BGP Preference: 170/-101
Next hop type: Unusable
Address: 0x903c184
Next-hop reference count: 1
State: <Hidden Int Ext>
Local AS: 200 Peer AS: 200
Age: 15
Validation State: unverified
Task: BGP_200.2001:db8:2::15+179
AS path: 100 I
Accepted
Localpref: 100
Router ID: 2.2.2.2
Indirect next hops: 1
Protocol next hop: 2001:db8:2::d <---------- R1's IP
Indirect next hop: 0 - INH Session ID: 0x0
After applying policy:-
+++++++++++++++++++
root@R3# run show route protocol bgp
inet.0: 14 destinations, 14 routes (14 active, 0 holddown, 0 hidden)
inet6.0: 19 destinations, 23 routes (19 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
::/0 *[BGP/170] 00:00:18, localpref 100
AS path: 100 I, validation-state: unverified
> to 2001:db8:2::15 via ge-0/0/5.0 <----------
[edit]
root@R3# run show route protocol bgp extensive
inet.0: 14 destinations, 14 routes (14 active, 0 holddown, 0 hidden)
inet6.0: 19 destinations, 23 routes (19 active, 0 holddown, 0 hidden)
::/0 (1 entry, 1 announced)
TSI:
KRT in-kernel ::/0 -> {indirect(262142)}
*BGP Preference: 170/-101
Next hop type: Indirect
Address: 0x92a8a28
Next-hop reference count: 3
Source: 2001:db8:2::15
Next hop type: Router, Next hop index: 618
Next hop: 2001:db8:2::15 via ge-0/0/5.0, selected
Session Id: 0x2
Protocol next hop: 2001:db8:2::15
Indirect next hop: 9124d00 262142 INH Session ID: 0x3
State: <Active Int Ext>
Local AS: 200 Peer AS: 200
Age: 40 Metric2: 0
Validation State: unverified
Task: BGP_200.2001:db8:2::15+179
Announcement bits (2): 0-KRT 2-Resolve tree 1
AS path: 100 I
Accepted
Localpref: 100
Router ID: 2.2.2.2
Indirect next hops: 1
Protocol next hop: 2001:db8:2::15 <------------- R2 peeing IP to R3
Indirect next hop: 9124d00 262142 INH Session ID: 0x3
Indirect path forwarding next hops: 1
Next hop type: Router
Next hop: 2001:db8:2::15 via ge-0/0/5.0
Session Id: 0x2
2001:db8:2::14/126 Originating RIB: inet6.0
Node path count: 1
Forwarding nexthops: 1
Next hop type: Interface
Nexthop: via ge-0/0/5.0
[edit]
root@R3#