Re: [ovs-dev] [PATCH] ofproto-dpif-xlate: native tunnel using valid tun_src specified by flow or port options

2018-04-15 Thread wenxu
OK Thx! I will modify it and resend this patch.








At 2018-04-14 05:21:17, "Ben Pfaff"  wrote:
>OK.  I think I understand the patch now.  It makes OVS native tunneling
>honor tunnel-specified source addresses, in the same way that Linux
>kernel tunneling honors them.
>
>I see one potential problem: it makes ovs-router.c #include
>.  This is a problem because ovs-router.c is used on
>Windows and BSD as well as on Linux, and those systems do not have
>rtnetlink.h or RTN_LOCAL.  Would you please change the patch to avoid
>this problem?
>
>Thank you for the contribution.  It will make OVS native tunneling
>better.
>
>On Sat, Feb 03, 2018 at 08:47:41AM +0800, wenxu wrote:
>> Hi ben,
>> 
>> 
>> This patch can be a bugfix.  
>> The tunnel_src of packet maybe not  the IP address set by gre port 
>> options:local_ip
>> dpdk-br has two address 10.1.1.7/24 and 10.1.1.254/32
>> Interface gre  options:local_ip="10.1.1.254"
>> But the tunnel_src of tunnel packet is always 10.1.1.7 
>> 
>> 
>> Also It can be a new feature.
>> In the same case the kernel space Open vSwitch  can send packet with 
>> tunnel_src 10.1.1.254.
>> 
>> 
>> Why we need this?
>> In the High-availability cluster
>> server1 with IP 10.1.1.7/24 and a virtual IP 10.1.1.254
>> server2 with IP 10.1.1.8/24  and a virtual IP 10.1.1.254
>> 
>> 
>> 10.1.1.7 and 10.1.1.8 running for the bgp and 10.1.1.254 provide the 
>> dataplane forward
>> 
>> 
>> 
>> 
>> At 2018-02-03 06:30:51, "Ben Pfaff"  wrote:
>> >Thank you for submitting a patch to improve Open vSwitch.  I do not yet
>> >understand the purpose of this patch.  Is it a bug fix or a new feature?
>> >
>> >Thanks,
>> >
>> >Ben.
>> >
>> >On Fri, Feb 02, 2018 at 02:08:52PM +0800, we...@ucloud.cn wrote:
>> >> From: wenxu 
>> >> 
>> >> native tunnel build tunnel with tun_src only from the route src and
>> >> not care about the options:local_ip.
>> >> Sometimes an virtual IP using for tun_src
>> >> dpdk-br:
>> >> inet 10.1.1.7/24 brd 10.1.1.255 scope global dpdk-br
>> >> inet 10.1.1.254/32 scope global dpdk-br
>> >> 
>> >> Interface: gre  options: {key=flow, local_ip="10.1.1.254", remote_ip=flow}
>> >> 
>> >> the native tunnel always using 10.1.1.7 as the tunnel_src but not 
>> >> 10.1.1.254.
>> >> 
>> >> This patch made valid tun_src specified by flow-action or gre port options
>> >> can be used for tunnel_src of packet. It stores the rtm_type for each 
>> >> route
>> >> and improve the priority RTN_LOCAL type(higher then userdef route).
>> >> Like the kernel space when lookup the route, if there are tun_src 
>> >> specified
>> >> by flow-action or port options. Check the tun_src wheather is a local
>> >> address, then lookup the route.
>> >> 
>> >> Signed-off-by: wenxu 
>> >> Signed-off-by: frank.zeng 
>> >> ---
>> >>  lib/ovs-router.c |   38 
>> >> +++---
>> >>  lib/ovs-router.h |2 +-
>> >>  lib/route-table.c|   10 --
>> >>  ofproto/ofproto-dpif-sflow.c |2 +-
>> >>  ofproto/ofproto-dpif-xlate.c |4 
>> >>  5 files changed, 45 insertions(+), 11 deletions(-)
>> >> 
>> >> diff --git a/lib/ovs-router.c b/lib/ovs-router.c
>> >> index 0f1103b..e1375a3 100644
>> >> --- a/lib/ovs-router.c
>> >> +++ b/lib/ovs-router.c
>> >> @@ -29,6 +29,7 @@
>> >>  #include 
>> >>  #include 
>> >>  #include 
>> >> +#include 
>> >>  
>> >>  #include "classifier.h"
>> >>  #include "command-line.h"
>> >> @@ -61,6 +62,7 @@ struct ovs_router_entry {
>> >>  struct in6_addr nw_addr;
>> >>  struct in6_addr src_addr;
>> >>  uint8_t plen;
>> >> +uint8_t rtm_type;
>> >>  uint8_t priority;
>> >>  uint32_t mark;
>> >>  };
>> >> @@ -97,13 +99,28 @@ ovs_router_lookup(uint32_t mark, const struct 
>> >> in6_addr *ip6_dst,
>> >>  const struct cls_rule *cr;
>> >>  struct flow flow = {.ipv6_dst = *ip6_dst, .pkt_mark = mark};
>> >>  
>> >> +if (src && ipv6_addr_is_set(src)) {
>> >> +const struct cls_rule *cr_src;
>> >> +struct flow flow_src = {.ipv6_dst = *src, .pkt_mark = mark};
>> >> +
>> >> +cr_src = classifier_lookup(, OVS_VERSION_MAX, _src, 
>> >> NULL);
>> >> +if (cr_src) {
>> >> +struct ovs_router_entry *p_src = 
>> >> ovs_router_entry_cast(cr_src);
>> >> +if (p_src->rtm_type != RTN_LOCAL) {
>> >> +return false;
>> >> +}
>> >> +} else {
>> >> +return false;
>> >> +}
>> >> +}
>> >> +
>> >>  cr = classifier_lookup(, OVS_VERSION_MAX, , NULL);
>> >>  if (cr) {
>> >>  struct ovs_router_entry *p = ovs_router_entry_cast(cr);
>> >>  
>> >>  ovs_strlcpy(output_bridge, p->output_bridge, IFNAMSIZ);
>> >>  *gw = p->gw;
>> >> -if (src) {
>> >> +if (src && !ipv6_addr_is_set(src)) {
>> >>  *src = p->src_addr;
>> >>  }
>> >>  return true;
>> >> @@ -184,7 +201,7 

Re: [ovs-dev] [PATCH] ofproto-dpif-xlate: native tunnel using valid tun_src specified by flow or port options

2018-04-13 Thread Ben Pfaff
OK.  I think I understand the patch now.  It makes OVS native tunneling
honor tunnel-specified source addresses, in the same way that Linux
kernel tunneling honors them.

I see one potential problem: it makes ovs-router.c #include
.  This is a problem because ovs-router.c is used on
Windows and BSD as well as on Linux, and those systems do not have
rtnetlink.h or RTN_LOCAL.  Would you please change the patch to avoid
this problem?

Thank you for the contribution.  It will make OVS native tunneling
better.

On Sat, Feb 03, 2018 at 08:47:41AM +0800, wenxu wrote:
> Hi ben,
> 
> 
> This patch can be a bugfix.  
> The tunnel_src of packet maybe not  the IP address set by gre port 
> options:local_ip
> dpdk-br has two address 10.1.1.7/24 and 10.1.1.254/32
> Interface gre  options:local_ip="10.1.1.254"
> But the tunnel_src of tunnel packet is always 10.1.1.7 
> 
> 
> Also It can be a new feature.
> In the same case the kernel space Open vSwitch  can send packet with 
> tunnel_src 10.1.1.254.
> 
> 
> Why we need this?
> In the High-availability cluster
> server1 with IP 10.1.1.7/24 and a virtual IP 10.1.1.254
> server2 with IP 10.1.1.8/24  and a virtual IP 10.1.1.254
> 
> 
> 10.1.1.7 and 10.1.1.8 running for the bgp and 10.1.1.254 provide the 
> dataplane forward
> 
> 
> 
> 
> At 2018-02-03 06:30:51, "Ben Pfaff"  wrote:
> >Thank you for submitting a patch to improve Open vSwitch.  I do not yet
> >understand the purpose of this patch.  Is it a bug fix or a new feature?
> >
> >Thanks,
> >
> >Ben.
> >
> >On Fri, Feb 02, 2018 at 02:08:52PM +0800, we...@ucloud.cn wrote:
> >> From: wenxu 
> >> 
> >> native tunnel build tunnel with tun_src only from the route src and
> >> not care about the options:local_ip.
> >> Sometimes an virtual IP using for tun_src
> >> dpdk-br:
> >> inet 10.1.1.7/24 brd 10.1.1.255 scope global dpdk-br
> >> inet 10.1.1.254/32 scope global dpdk-br
> >> 
> >> Interface: gre  options: {key=flow, local_ip="10.1.1.254", remote_ip=flow}
> >> 
> >> the native tunnel always using 10.1.1.7 as the tunnel_src but not 
> >> 10.1.1.254.
> >> 
> >> This patch made valid tun_src specified by flow-action or gre port options
> >> can be used for tunnel_src of packet. It stores the rtm_type for each route
> >> and improve the priority RTN_LOCAL type(higher then userdef route).
> >> Like the kernel space when lookup the route, if there are tun_src specified
> >> by flow-action or port options. Check the tun_src wheather is a local
> >> address, then lookup the route.
> >> 
> >> Signed-off-by: wenxu 
> >> Signed-off-by: frank.zeng 
> >> ---
> >>  lib/ovs-router.c |   38 +++---
> >>  lib/ovs-router.h |2 +-
> >>  lib/route-table.c|   10 --
> >>  ofproto/ofproto-dpif-sflow.c |2 +-
> >>  ofproto/ofproto-dpif-xlate.c |4 
> >>  5 files changed, 45 insertions(+), 11 deletions(-)
> >> 
> >> diff --git a/lib/ovs-router.c b/lib/ovs-router.c
> >> index 0f1103b..e1375a3 100644
> >> --- a/lib/ovs-router.c
> >> +++ b/lib/ovs-router.c
> >> @@ -29,6 +29,7 @@
> >>  #include 
> >>  #include 
> >>  #include 
> >> +#include 
> >>  
> >>  #include "classifier.h"
> >>  #include "command-line.h"
> >> @@ -61,6 +62,7 @@ struct ovs_router_entry {
> >>  struct in6_addr nw_addr;
> >>  struct in6_addr src_addr;
> >>  uint8_t plen;
> >> +uint8_t rtm_type;
> >>  uint8_t priority;
> >>  uint32_t mark;
> >>  };
> >> @@ -97,13 +99,28 @@ ovs_router_lookup(uint32_t mark, const struct in6_addr 
> >> *ip6_dst,
> >>  const struct cls_rule *cr;
> >>  struct flow flow = {.ipv6_dst = *ip6_dst, .pkt_mark = mark};
> >>  
> >> +if (src && ipv6_addr_is_set(src)) {
> >> +const struct cls_rule *cr_src;
> >> +struct flow flow_src = {.ipv6_dst = *src, .pkt_mark = mark};
> >> +
> >> +cr_src = classifier_lookup(, OVS_VERSION_MAX, _src, 
> >> NULL);
> >> +if (cr_src) {
> >> +struct ovs_router_entry *p_src = 
> >> ovs_router_entry_cast(cr_src);
> >> +if (p_src->rtm_type != RTN_LOCAL) {
> >> +return false;
> >> +}
> >> +} else {
> >> +return false;
> >> +}
> >> +}
> >> +
> >>  cr = classifier_lookup(, OVS_VERSION_MAX, , NULL);
> >>  if (cr) {
> >>  struct ovs_router_entry *p = ovs_router_entry_cast(cr);
> >>  
> >>  ovs_strlcpy(output_bridge, p->output_bridge, IFNAMSIZ);
> >>  *gw = p->gw;
> >> -if (src) {
> >> +if (src && !ipv6_addr_is_set(src)) {
> >>  *src = p->src_addr;
> >>  }
> >>  return true;
> >> @@ -184,7 +201,7 @@ out:
> >>  }
> >>  
> >>  static int
> >> -ovs_router_insert__(uint32_t mark, uint8_t priority,
> >> +ovs_router_insert__(uint32_t mark, uint8_t priority, uint8_t rtm_type,
> >>  const struct in6_addr *ip6_dst,
> >>  uint8_t 

Re: [ovs-dev] [PATCH] ofproto-dpif-xlate: native tunnel using valid tun_src specified by flow or port options

2018-02-20 Thread wenxu
Hi Ben,


Are there some idea for this patch?


BR
wenxu


在 2018-02-03 08:47:41,"wenxu"  写道:

Hi ben,


This patch can be a bugfix.  
The tunnel_src of packet maybe not  the IP address set by gre port 
options:local_ip
dpdk-br has two address 10.1.1.7/24 and 10.1.1.254/32
Interface gre  options:local_ip="10.1.1.254"
But the tunnel_src of tunnel packet is always 10.1.1.7 


Also It can be a new feature.
In the same case the kernel space Open vSwitch  can send packet with tunnel_src 
10.1.1.254.


Why we need this?
In the High-availability cluster
server1 with IP 10.1.1.7/24 and a virtual IP 10.1.1.254
server2 with IP 10.1.1.8/24  and a virtual IP 10.1.1.254


10.1.1.7 and 10.1.1.8 running for the bgp and 10.1.1.254 provide the dataplane 
forward




At 2018-02-03 06:30:51, "Ben Pfaff"  wrote:
>Thank you for submitting a patch to improve Open vSwitch.  I do not yet
>understand the purpose of this patch.  Is it a bug fix or a new feature?
>
>Thanks,
>
>Ben.
>
>On Fri, Feb 02, 2018 at 02:08:52PM +0800, we...@ucloud.cn wrote:
>> From: wenxu 
>> 
>> native tunnel build tunnel with tun_src only from the route src and
>> not care about the options:local_ip.
>> Sometimes an virtual IP using for tun_src
>> dpdk-br:
>> inet 10.1.1.7/24 brd 10.1.1.255 scope global dpdk-br
>> inet 10.1.1.254/32 scope global dpdk-br
>> 
>> Interface: gre  options: {key=flow, local_ip="10.1.1.254", remote_ip=flow}
>> 
>> the native tunnel always using 10.1.1.7 as the tunnel_src but not 10.1.1.254.
>> 
>> This patch made valid tun_src specified by flow-action or gre port options
>> can be used for tunnel_src of packet. It stores the rtm_type for each route
>> and improve the priority RTN_LOCAL type(higher then userdef route).
>> Like the kernel space when lookup the route, if there are tun_src specified
>> by flow-action or port options. Check the tun_src wheather is a local
>> address, then lookup the route.
>> 
>> Signed-off-by: wenxu 
>> Signed-off-by: frank.zeng 
>> ---
>>  lib/ovs-router.c |   38 +++---
>>  lib/ovs-router.h |2 +-
>>  lib/route-table.c|   10 --
>>  ofproto/ofproto-dpif-sflow.c |2 +-
>>  ofproto/ofproto-dpif-xlate.c |4 
>>  5 files changed, 45 insertions(+), 11 deletions(-)
>> 
>> diff --git a/lib/ovs-router.c b/lib/ovs-router.c
>> index 0f1103b..e1375a3 100644
>> --- a/lib/ovs-router.c
>> +++ b/lib/ovs-router.c
>> @@ -29,6 +29,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  
>>  #include "classifier.h"
>>  #include "command-line.h"
>> @@ -61,6 +62,7 @@ struct ovs_router_entry {
>>  struct in6_addr nw_addr;
>>  struct in6_addr src_addr;
>>  uint8_t plen;
>> +uint8_t rtm_type;
>>  uint8_t priority;
>>  uint32_t mark;
>>  };
>> @@ -97,13 +99,28 @@ ovs_router_lookup(uint32_t mark, const struct in6_addr 
>> *ip6_dst,
>>  const struct cls_rule *cr;
>>  struct flow flow = {.ipv6_dst = *ip6_dst, .pkt_mark = mark};
>>  
>> +if (src && ipv6_addr_is_set(src)) {
>> +const struct cls_rule *cr_src;
>> +struct flow flow_src = {.ipv6_dst = *src, .pkt_mark = mark};
>> +
>> +cr_src = classifier_lookup(, OVS_VERSION_MAX, _src, NULL);
>> +if (cr_src) {
>> +struct ovs_router_entry *p_src = ovs_router_entry_cast(cr_src);
>> +if (p_src->rtm_type != RTN_LOCAL) {
>> +return false;
>> +}
>> +} else {
>> +return false;
>> +}
>> +}
>> +
>>  cr = classifier_lookup(, OVS_VERSION_MAX, , NULL);
>>  if (cr) {
>>  struct ovs_router_entry *p = ovs_router_entry_cast(cr);
>>  
>>  ovs_strlcpy(output_bridge, p->output_bridge, IFNAMSIZ);
>>  *gw = p->gw;
>> -if (src) {
>> +if (src && !ipv6_addr_is_set(src)) {
>>  *src = p->src_addr;
>>  }
>>  return true;
>> @@ -184,7 +201,7 @@ out:
>>  }
>>  
>>  static int
>> -ovs_router_insert__(uint32_t mark, uint8_t priority,
>> +ovs_router_insert__(uint32_t mark, uint8_t priority, uint8_t rtm_type,
>>  const struct in6_addr *ip6_dst,
>>  uint8_t plen, const char output_bridge[],
>>  const struct in6_addr *gw)
>> @@ -204,6 +221,7 @@ ovs_router_insert__(uint32_t mark, uint8_t priority,
>>  p->mark = mark;
>>  p->nw_addr = match.flow.ipv6_dst;
>>  p->plen = plen;
>> +p->rtm_type = rtm_type;
>>  p->priority = priority;
>>  err = get_src_addr(ip6_dst, output_bridge, >src_addr);
>>  if (err && ipv6_addr_is_set(gw)) {
>> @@ -236,9 +254,10 @@ ovs_router_insert__(uint32_t mark, uint8_t priority,
>>  
>>  void
>>  ovs_router_insert(uint32_t mark, const struct in6_addr *ip_dst, uint8_t 
>> plen,
>> -  const char output_bridge[], const struct in6_addr *gw)
>> +  uint8_t rtm_type, const char 

Re: [ovs-dev] [PATCH] ofproto-dpif-xlate: native tunnel using valid tun_src specified by flow or port options

2018-02-02 Thread wenxu
Hi ben,


This patch can be a bugfix.  
The tunnel_src of packet maybe not  the IP address set by gre port 
options:local_ip
dpdk-br has two address 10.1.1.7/24 and 10.1.1.254/32
Interface gre  options:local_ip="10.1.1.254"
But the tunnel_src of tunnel packet is always 10.1.1.7 


Also It can be a new feature.
In the same case the kernel space Open vSwitch  can send packet with tunnel_src 
10.1.1.254.


Why we need this?
In the High-availability cluster
server1 with IP 10.1.1.7/24 and a virtual IP 10.1.1.254
server2 with IP 10.1.1.8/24  and a virtual IP 10.1.1.254


10.1.1.7 and 10.1.1.8 running for the bgp and 10.1.1.254 provide the dataplane 
forward




At 2018-02-03 06:30:51, "Ben Pfaff"  wrote:
>Thank you for submitting a patch to improve Open vSwitch.  I do not yet
>understand the purpose of this patch.  Is it a bug fix or a new feature?
>
>Thanks,
>
>Ben.
>
>On Fri, Feb 02, 2018 at 02:08:52PM +0800, we...@ucloud.cn wrote:
>> From: wenxu 
>> 
>> native tunnel build tunnel with tun_src only from the route src and
>> not care about the options:local_ip.
>> Sometimes an virtual IP using for tun_src
>> dpdk-br:
>> inet 10.1.1.7/24 brd 10.1.1.255 scope global dpdk-br
>> inet 10.1.1.254/32 scope global dpdk-br
>> 
>> Interface: gre  options: {key=flow, local_ip="10.1.1.254", remote_ip=flow}
>> 
>> the native tunnel always using 10.1.1.7 as the tunnel_src but not 10.1.1.254.
>> 
>> This patch made valid tun_src specified by flow-action or gre port options
>> can be used for tunnel_src of packet. It stores the rtm_type for each route
>> and improve the priority RTN_LOCAL type(higher then userdef route).
>> Like the kernel space when lookup the route, if there are tun_src specified
>> by flow-action or port options. Check the tun_src wheather is a local
>> address, then lookup the route.
>> 
>> Signed-off-by: wenxu 
>> Signed-off-by: frank.zeng 
>> ---
>>  lib/ovs-router.c |   38 +++---
>>  lib/ovs-router.h |2 +-
>>  lib/route-table.c|   10 --
>>  ofproto/ofproto-dpif-sflow.c |2 +-
>>  ofproto/ofproto-dpif-xlate.c |4 
>>  5 files changed, 45 insertions(+), 11 deletions(-)
>> 
>> diff --git a/lib/ovs-router.c b/lib/ovs-router.c
>> index 0f1103b..e1375a3 100644
>> --- a/lib/ovs-router.c
>> +++ b/lib/ovs-router.c
>> @@ -29,6 +29,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  
>>  #include "classifier.h"
>>  #include "command-line.h"
>> @@ -61,6 +62,7 @@ struct ovs_router_entry {
>>  struct in6_addr nw_addr;
>>  struct in6_addr src_addr;
>>  uint8_t plen;
>> +uint8_t rtm_type;
>>  uint8_t priority;
>>  uint32_t mark;
>>  };
>> @@ -97,13 +99,28 @@ ovs_router_lookup(uint32_t mark, const struct in6_addr 
>> *ip6_dst,
>>  const struct cls_rule *cr;
>>  struct flow flow = {.ipv6_dst = *ip6_dst, .pkt_mark = mark};
>>  
>> +if (src && ipv6_addr_is_set(src)) {
>> +const struct cls_rule *cr_src;
>> +struct flow flow_src = {.ipv6_dst = *src, .pkt_mark = mark};
>> +
>> +cr_src = classifier_lookup(, OVS_VERSION_MAX, _src, NULL);
>> +if (cr_src) {
>> +struct ovs_router_entry *p_src = ovs_router_entry_cast(cr_src);
>> +if (p_src->rtm_type != RTN_LOCAL) {
>> +return false;
>> +}
>> +} else {
>> +return false;
>> +}
>> +}
>> +
>>  cr = classifier_lookup(, OVS_VERSION_MAX, , NULL);
>>  if (cr) {
>>  struct ovs_router_entry *p = ovs_router_entry_cast(cr);
>>  
>>  ovs_strlcpy(output_bridge, p->output_bridge, IFNAMSIZ);
>>  *gw = p->gw;
>> -if (src) {
>> +if (src && !ipv6_addr_is_set(src)) {
>>  *src = p->src_addr;
>>  }
>>  return true;
>> @@ -184,7 +201,7 @@ out:
>>  }
>>  
>>  static int
>> -ovs_router_insert__(uint32_t mark, uint8_t priority,
>> +ovs_router_insert__(uint32_t mark, uint8_t priority, uint8_t rtm_type,
>>  const struct in6_addr *ip6_dst,
>>  uint8_t plen, const char output_bridge[],
>>  const struct in6_addr *gw)
>> @@ -204,6 +221,7 @@ ovs_router_insert__(uint32_t mark, uint8_t priority,
>>  p->mark = mark;
>>  p->nw_addr = match.flow.ipv6_dst;
>>  p->plen = plen;
>> +p->rtm_type = rtm_type;
>>  p->priority = priority;
>>  err = get_src_addr(ip6_dst, output_bridge, >src_addr);
>>  if (err && ipv6_addr_is_set(gw)) {
>> @@ -236,9 +254,10 @@ ovs_router_insert__(uint32_t mark, uint8_t priority,
>>  
>>  void
>>  ovs_router_insert(uint32_t mark, const struct in6_addr *ip_dst, uint8_t 
>> plen,
>> -  const char output_bridge[], const struct in6_addr *gw)
>> +  uint8_t rtm_type, const char output_bridge[], 
>> +  const struct in6_addr *gw)
>>  {
>> -ovs_router_insert__(mark, plen, 

Re: [ovs-dev] [PATCH] ofproto-dpif-xlate: native tunnel using valid tun_src specified by flow or port options

2018-02-02 Thread Ben Pfaff
Thank you for submitting a patch to improve Open vSwitch.  I do not yet
understand the purpose of this patch.  Is it a bug fix or a new feature?

Thanks,

Ben.

On Fri, Feb 02, 2018 at 02:08:52PM +0800, we...@ucloud.cn wrote:
> From: wenxu 
> 
> native tunnel build tunnel with tun_src only from the route src and
> not care about the options:local_ip.
> Sometimes an virtual IP using for tun_src
> dpdk-br:
> inet 10.1.1.7/24 brd 10.1.1.255 scope global dpdk-br
> inet 10.1.1.254/32 scope global dpdk-br
> 
> Interface: gre  options: {key=flow, local_ip="10.1.1.254", remote_ip=flow}
> 
> the native tunnel always using 10.1.1.7 as the tunnel_src but not 10.1.1.254.
> 
> This patch made valid tun_src specified by flow-action or gre port options
> can be used for tunnel_src of packet. It stores the rtm_type for each route
> and improve the priority RTN_LOCAL type(higher then userdef route).
> Like the kernel space when lookup the route, if there are tun_src specified
> by flow-action or port options. Check the tun_src wheather is a local
> address, then lookup the route.
> 
> Signed-off-by: wenxu 
> Signed-off-by: frank.zeng 
> ---
>  lib/ovs-router.c |   38 +++---
>  lib/ovs-router.h |2 +-
>  lib/route-table.c|   10 --
>  ofproto/ofproto-dpif-sflow.c |2 +-
>  ofproto/ofproto-dpif-xlate.c |4 
>  5 files changed, 45 insertions(+), 11 deletions(-)
> 
> diff --git a/lib/ovs-router.c b/lib/ovs-router.c
> index 0f1103b..e1375a3 100644
> --- a/lib/ovs-router.c
> +++ b/lib/ovs-router.c
> @@ -29,6 +29,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include "classifier.h"
>  #include "command-line.h"
> @@ -61,6 +62,7 @@ struct ovs_router_entry {
>  struct in6_addr nw_addr;
>  struct in6_addr src_addr;
>  uint8_t plen;
> +uint8_t rtm_type;
>  uint8_t priority;
>  uint32_t mark;
>  };
> @@ -97,13 +99,28 @@ ovs_router_lookup(uint32_t mark, const struct in6_addr 
> *ip6_dst,
>  const struct cls_rule *cr;
>  struct flow flow = {.ipv6_dst = *ip6_dst, .pkt_mark = mark};
>  
> +if (src && ipv6_addr_is_set(src)) {
> +const struct cls_rule *cr_src;
> +struct flow flow_src = {.ipv6_dst = *src, .pkt_mark = mark};
> +
> +cr_src = classifier_lookup(, OVS_VERSION_MAX, _src, NULL);
> +if (cr_src) {
> +struct ovs_router_entry *p_src = ovs_router_entry_cast(cr_src);
> +if (p_src->rtm_type != RTN_LOCAL) {
> +return false;
> +}
> +} else {
> +return false;
> +}
> +}
> +
>  cr = classifier_lookup(, OVS_VERSION_MAX, , NULL);
>  if (cr) {
>  struct ovs_router_entry *p = ovs_router_entry_cast(cr);
>  
>  ovs_strlcpy(output_bridge, p->output_bridge, IFNAMSIZ);
>  *gw = p->gw;
> -if (src) {
> +if (src && !ipv6_addr_is_set(src)) {
>  *src = p->src_addr;
>  }
>  return true;
> @@ -184,7 +201,7 @@ out:
>  }
>  
>  static int
> -ovs_router_insert__(uint32_t mark, uint8_t priority,
> +ovs_router_insert__(uint32_t mark, uint8_t priority, uint8_t rtm_type,
>  const struct in6_addr *ip6_dst,
>  uint8_t plen, const char output_bridge[],
>  const struct in6_addr *gw)
> @@ -204,6 +221,7 @@ ovs_router_insert__(uint32_t mark, uint8_t priority,
>  p->mark = mark;
>  p->nw_addr = match.flow.ipv6_dst;
>  p->plen = plen;
> +p->rtm_type = rtm_type;
>  p->priority = priority;
>  err = get_src_addr(ip6_dst, output_bridge, >src_addr);
>  if (err && ipv6_addr_is_set(gw)) {
> @@ -236,9 +254,10 @@ ovs_router_insert__(uint32_t mark, uint8_t priority,
>  
>  void
>  ovs_router_insert(uint32_t mark, const struct in6_addr *ip_dst, uint8_t plen,
> -  const char output_bridge[], const struct in6_addr *gw)
> +  uint8_t rtm_type, const char output_bridge[], 
> +  const struct in6_addr *gw)
>  {
> -ovs_router_insert__(mark, plen, ip_dst, plen, output_bridge, gw);
> +ovs_router_insert__(mark, plen, rtm_type, ip_dst, plen, output_bridge, 
> gw);
>  }
>  
>  static void
> @@ -345,7 +364,7 @@ ovs_router_add(struct unixctl_conn *conn, int argc,
>  }
>  }
>  
> -err = ovs_router_insert__(mark, plen + 32, , plen, argv[2], );
> +err = ovs_router_insert__(mark, plen + 32, RTN_UNICAST, , plen, 
> argv[2], );
>  if (err) {
>  unixctl_command_reply_error(conn, "Error while inserting route.");
>  } else {
> @@ -402,7 +421,12 @@ ovs_router_show(struct unixctl_conn *conn, int argc 
> OVS_UNUSED,
>  ipv6_format_mapped(>nw_addr, );
>  plen = rt->plen;
>  if (IN6_IS_ADDR_V4MAPPED(>nw_addr)) {
> -plen -= 96;
> +uint8_t plen_off = 96;
> +
> +if (rt->rtm_type == RTN_LOCAL) {
> +  

[ovs-dev] [PATCH] ofproto-dpif-xlate: native tunnel using valid tun_src specified by flow or port options

2018-02-01 Thread wenxu
From: wenxu 

native tunnel build tunnel with tun_src only from the route src and
not care about the options:local_ip.
Sometimes an virtual IP using for tun_src
dpdk-br:
inet 10.1.1.7/24 brd 10.1.1.255 scope global dpdk-br
inet 10.1.1.254/32 scope global dpdk-br

Interface: gre  options: {key=flow, local_ip="10.1.1.254", remote_ip=flow}

the native tunnel always using 10.1.1.7 as the tunnel_src but not 10.1.1.254.

This patch made valid tun_src specified by flow-action or gre port options
can be used for tunnel_src of packet. It stores the rtm_type for each route
and improve the priority RTN_LOCAL type(higher then userdef route).
Like the kernel space when lookup the route, if there are tun_src specified
by flow-action or port options. Check the tun_src wheather is a local
address, then lookup the route.

Signed-off-by: wenxu 
Signed-off-by: frank.zeng 
---
 lib/ovs-router.c |   38 +++---
 lib/ovs-router.h |2 +-
 lib/route-table.c|   10 --
 ofproto/ofproto-dpif-sflow.c |2 +-
 ofproto/ofproto-dpif-xlate.c |4 
 5 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/lib/ovs-router.c b/lib/ovs-router.c
index 0f1103b..e1375a3 100644
--- a/lib/ovs-router.c
+++ b/lib/ovs-router.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "classifier.h"
 #include "command-line.h"
@@ -61,6 +62,7 @@ struct ovs_router_entry {
 struct in6_addr nw_addr;
 struct in6_addr src_addr;
 uint8_t plen;
+uint8_t rtm_type;
 uint8_t priority;
 uint32_t mark;
 };
@@ -97,13 +99,28 @@ ovs_router_lookup(uint32_t mark, const struct in6_addr 
*ip6_dst,
 const struct cls_rule *cr;
 struct flow flow = {.ipv6_dst = *ip6_dst, .pkt_mark = mark};
 
+if (src && ipv6_addr_is_set(src)) {
+const struct cls_rule *cr_src;
+struct flow flow_src = {.ipv6_dst = *src, .pkt_mark = mark};
+
+cr_src = classifier_lookup(, OVS_VERSION_MAX, _src, NULL);
+if (cr_src) {
+struct ovs_router_entry *p_src = ovs_router_entry_cast(cr_src);
+if (p_src->rtm_type != RTN_LOCAL) {
+return false;
+}
+} else {
+return false;
+}
+}
+
 cr = classifier_lookup(, OVS_VERSION_MAX, , NULL);
 if (cr) {
 struct ovs_router_entry *p = ovs_router_entry_cast(cr);
 
 ovs_strlcpy(output_bridge, p->output_bridge, IFNAMSIZ);
 *gw = p->gw;
-if (src) {
+if (src && !ipv6_addr_is_set(src)) {
 *src = p->src_addr;
 }
 return true;
@@ -184,7 +201,7 @@ out:
 }
 
 static int
-ovs_router_insert__(uint32_t mark, uint8_t priority,
+ovs_router_insert__(uint32_t mark, uint8_t priority, uint8_t rtm_type,
 const struct in6_addr *ip6_dst,
 uint8_t plen, const char output_bridge[],
 const struct in6_addr *gw)
@@ -204,6 +221,7 @@ ovs_router_insert__(uint32_t mark, uint8_t priority,
 p->mark = mark;
 p->nw_addr = match.flow.ipv6_dst;
 p->plen = plen;
+p->rtm_type = rtm_type;
 p->priority = priority;
 err = get_src_addr(ip6_dst, output_bridge, >src_addr);
 if (err && ipv6_addr_is_set(gw)) {
@@ -236,9 +254,10 @@ ovs_router_insert__(uint32_t mark, uint8_t priority,
 
 void
 ovs_router_insert(uint32_t mark, const struct in6_addr *ip_dst, uint8_t plen,
-  const char output_bridge[], const struct in6_addr *gw)
+  uint8_t rtm_type, const char output_bridge[], 
+  const struct in6_addr *gw)
 {
-ovs_router_insert__(mark, plen, ip_dst, plen, output_bridge, gw);
+ovs_router_insert__(mark, plen, rtm_type, ip_dst, plen, output_bridge, gw);
 }
 
 static void
@@ -345,7 +364,7 @@ ovs_router_add(struct unixctl_conn *conn, int argc,
 }
 }
 
-err = ovs_router_insert__(mark, plen + 32, , plen, argv[2], );
+err = ovs_router_insert__(mark, plen + 32, RTN_UNICAST, , plen, 
argv[2], );
 if (err) {
 unixctl_command_reply_error(conn, "Error while inserting route.");
 } else {
@@ -402,7 +421,12 @@ ovs_router_show(struct unixctl_conn *conn, int argc 
OVS_UNUSED,
 ipv6_format_mapped(>nw_addr, );
 plen = rt->plen;
 if (IN6_IS_ADDR_V4MAPPED(>nw_addr)) {
-plen -= 96;
+uint8_t plen_off = 96;
+
+if (rt->rtm_type == RTN_LOCAL) {
+plen_off += 64;
+}
+plen -= plen_off;
 }
 ds_put_format(, "/%"PRIu8, plen);
 if (rt->mark) {
@@ -426,7 +450,7 @@ static void
 ovs_router_lookup_cmd(struct unixctl_conn *conn, int argc,
   const char *argv[], void *aux OVS_UNUSED)
 {
-struct in6_addr gw, src;
+struct in6_addr gw, src = in6addr_any;
 char iface[IFNAMSIZ];
 struct in6_addr ip6;
 unsigned int plen;
diff --git