diff options
| author | Fan Du <fan.du@intel.com> | 2015-01-14 00:10:35 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2015-01-14 16:32:06 -0500 |
| commit | 3f4c1d87af2a0c8a599b95bfebbc6338de343aca (patch) | |
| tree | eb8a54a9c56cec232bbebf303c18f749965a1e59 /net/openvswitch | |
| parent | 2733135329e9bbc306be9f58af1b4be92b359d23 (diff) | |
openvswitch: Introduce ovs_tunnel_route_lookup
Introduce ovs_tunnel_route_lookup to consolidate route lookup
shared by vxlan, gre, and geneve ports.
Signed-off-by: Fan Du <fan.du@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/openvswitch')
| -rw-r--r-- | net/openvswitch/vport-geneve.c | 13 | ||||
| -rw-r--r-- | net/openvswitch/vport-gre.c | 12 | ||||
| -rw-r--r-- | net/openvswitch/vport-vxlan.c | 12 | ||||
| -rw-r--r-- | net/openvswitch/vport.c | 9 | ||||
| -rw-r--r-- | net/openvswitch/vport.h | 18 |
5 files changed, 25 insertions, 39 deletions
diff --git a/net/openvswitch/vport-geneve.c b/net/openvswitch/vport-geneve.c index 2daf1440618b..88a010c98c05 100644 --- a/net/openvswitch/vport-geneve.c +++ b/net/openvswitch/vport-geneve.c | |||
| @@ -170,7 +170,7 @@ error: | |||
| 170 | 170 | ||
| 171 | static int geneve_tnl_send(struct vport *vport, struct sk_buff *skb) | 171 | static int geneve_tnl_send(struct vport *vport, struct sk_buff *skb) |
| 172 | { | 172 | { |
| 173 | struct ovs_key_ipv4_tunnel *tun_key; | 173 | const struct ovs_key_ipv4_tunnel *tun_key; |
| 174 | struct ovs_tunnel_info *tun_info; | 174 | struct ovs_tunnel_info *tun_info; |
| 175 | struct net *net = ovs_dp_get_net(vport->dp); | 175 | struct net *net = ovs_dp_get_net(vport->dp); |
| 176 | struct geneve_port *geneve_port = geneve_vport(vport); | 176 | struct geneve_port *geneve_port = geneve_vport(vport); |
| @@ -189,16 +189,7 @@ static int geneve_tnl_send(struct vport *vport, struct sk_buff *skb) | |||
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | tun_key = &tun_info->tunnel; | 191 | tun_key = &tun_info->tunnel; |
| 192 | 192 | rt = ovs_tunnel_route_lookup(net, tun_key, skb->mark, &fl, IPPROTO_UDP); | |
| 193 | /* Route lookup */ | ||
| 194 | memset(&fl, 0, sizeof(fl)); | ||
| 195 | fl.daddr = tun_key->ipv4_dst; | ||
| 196 | fl.saddr = tun_key->ipv4_src; | ||
| 197 | fl.flowi4_tos = RT_TOS(tun_key->ipv4_tos); | ||
| 198 | fl.flowi4_mark = skb->mark; | ||
| 199 | fl.flowi4_proto = IPPROTO_UDP; | ||
| 200 | |||
| 201 | rt = ip_route_output_key(net, &fl); | ||
| 202 | if (IS_ERR(rt)) { | 193 | if (IS_ERR(rt)) { |
| 203 | err = PTR_ERR(rt); | 194 | err = PTR_ERR(rt); |
| 204 | goto error; | 195 | goto error; |
diff --git a/net/openvswitch/vport-gre.c b/net/openvswitch/vport-gre.c index e9aedb7c7106..f17ac9642f4e 100644 --- a/net/openvswitch/vport-gre.c +++ b/net/openvswitch/vport-gre.c | |||
| @@ -134,7 +134,7 @@ static int gre_err(struct sk_buff *skb, u32 info, | |||
| 134 | static int gre_tnl_send(struct vport *vport, struct sk_buff *skb) | 134 | static int gre_tnl_send(struct vport *vport, struct sk_buff *skb) |
| 135 | { | 135 | { |
| 136 | struct net *net = ovs_dp_get_net(vport->dp); | 136 | struct net *net = ovs_dp_get_net(vport->dp); |
| 137 | struct ovs_key_ipv4_tunnel *tun_key; | 137 | const struct ovs_key_ipv4_tunnel *tun_key; |
| 138 | struct flowi4 fl; | 138 | struct flowi4 fl; |
| 139 | struct rtable *rt; | 139 | struct rtable *rt; |
| 140 | int min_headroom; | 140 | int min_headroom; |
| @@ -148,15 +148,7 @@ static int gre_tnl_send(struct vport *vport, struct sk_buff *skb) | |||
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | tun_key = &OVS_CB(skb)->egress_tun_info->tunnel; | 150 | tun_key = &OVS_CB(skb)->egress_tun_info->tunnel; |
| 151 | /* Route lookup */ | 151 | rt = ovs_tunnel_route_lookup(net, tun_key, skb->mark, &fl, IPPROTO_GRE); |
| 152 | memset(&fl, 0, sizeof(fl)); | ||
| 153 | fl.daddr = tun_key->ipv4_dst; | ||
| 154 | fl.saddr = tun_key->ipv4_src; | ||
| 155 | fl.flowi4_tos = RT_TOS(tun_key->ipv4_tos); | ||
| 156 | fl.flowi4_mark = skb->mark; | ||
| 157 | fl.flowi4_proto = IPPROTO_GRE; | ||
| 158 | |||
| 159 | rt = ip_route_output_key(net, &fl); | ||
| 160 | if (IS_ERR(rt)) { | 152 | if (IS_ERR(rt)) { |
| 161 | err = PTR_ERR(rt); | 153 | err = PTR_ERR(rt); |
| 162 | goto err_free_skb; | 154 | goto err_free_skb; |
diff --git a/net/openvswitch/vport-vxlan.c b/net/openvswitch/vport-vxlan.c index d7c46b301024..1435a053a870 100644 --- a/net/openvswitch/vport-vxlan.c +++ b/net/openvswitch/vport-vxlan.c | |||
| @@ -145,7 +145,7 @@ static int vxlan_tnl_send(struct vport *vport, struct sk_buff *skb) | |||
| 145 | struct net *net = ovs_dp_get_net(vport->dp); | 145 | struct net *net = ovs_dp_get_net(vport->dp); |
| 146 | struct vxlan_port *vxlan_port = vxlan_vport(vport); | 146 | struct vxlan_port *vxlan_port = vxlan_vport(vport); |
| 147 | __be16 dst_port = inet_sk(vxlan_port->vs->sock->sk)->inet_sport; | 147 | __be16 dst_port = inet_sk(vxlan_port->vs->sock->sk)->inet_sport; |
| 148 | struct ovs_key_ipv4_tunnel *tun_key; | 148 | const struct ovs_key_ipv4_tunnel *tun_key; |
| 149 | struct rtable *rt; | 149 | struct rtable *rt; |
| 150 | struct flowi4 fl; | 150 | struct flowi4 fl; |
| 151 | __be16 src_port; | 151 | __be16 src_port; |
| @@ -158,15 +158,7 @@ static int vxlan_tnl_send(struct vport *vport, struct sk_buff *skb) | |||
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | tun_key = &OVS_CB(skb)->egress_tun_info->tunnel; | 160 | tun_key = &OVS_CB(skb)->egress_tun_info->tunnel; |
| 161 | /* Route lookup */ | 161 | rt = ovs_tunnel_route_lookup(net, tun_key, skb->mark, &fl, IPPROTO_UDP); |
| 162 | memset(&fl, 0, sizeof(fl)); | ||
| 163 | fl.daddr = tun_key->ipv4_dst; | ||
| 164 | fl.saddr = tun_key->ipv4_src; | ||
| 165 | fl.flowi4_tos = RT_TOS(tun_key->ipv4_tos); | ||
| 166 | fl.flowi4_mark = skb->mark; | ||
| 167 | fl.flowi4_proto = IPPROTO_UDP; | ||
| 168 | |||
| 169 | rt = ip_route_output_key(net, &fl); | ||
| 170 | if (IS_ERR(rt)) { | 162 | if (IS_ERR(rt)) { |
| 171 | err = PTR_ERR(rt); | 163 | err = PTR_ERR(rt); |
| 172 | goto error; | 164 | goto error; |
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c index 464739aac0f3..ec2954ffc690 100644 --- a/net/openvswitch/vport.c +++ b/net/openvswitch/vport.c | |||
| @@ -595,14 +595,7 @@ int ovs_tunnel_get_egress_info(struct ovs_tunnel_info *egress_tun_info, | |||
| 595 | * The process may need to be changed if the corresponding process | 595 | * The process may need to be changed if the corresponding process |
| 596 | * in vports ops changed. | 596 | * in vports ops changed. |
| 597 | */ | 597 | */ |
| 598 | memset(&fl, 0, sizeof(fl)); | 598 | rt = ovs_tunnel_route_lookup(net, tun_key, skb_mark, &fl, ipproto); |
| 599 | fl.daddr = tun_key->ipv4_dst; | ||
| 600 | fl.saddr = tun_key->ipv4_src; | ||
| 601 | fl.flowi4_tos = RT_TOS(tun_key->ipv4_tos); | ||
| 602 | fl.flowi4_mark = skb_mark; | ||
| 603 | fl.flowi4_proto = ipproto; | ||
| 604 | |||
| 605 | rt = ip_route_output_key(net, &fl); | ||
| 606 | if (IS_ERR(rt)) | 599 | if (IS_ERR(rt)) |
| 607 | return PTR_ERR(rt); | 600 | return PTR_ERR(rt); |
| 608 | 601 | ||
diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h index 99c8e71d9e6c..f8ae295fb001 100644 --- a/net/openvswitch/vport.h +++ b/net/openvswitch/vport.h | |||
| @@ -236,4 +236,22 @@ static inline void ovs_skb_postpush_rcsum(struct sk_buff *skb, | |||
| 236 | int ovs_vport_ops_register(struct vport_ops *ops); | 236 | int ovs_vport_ops_register(struct vport_ops *ops); |
| 237 | void ovs_vport_ops_unregister(struct vport_ops *ops); | 237 | void ovs_vport_ops_unregister(struct vport_ops *ops); |
| 238 | 238 | ||
| 239 | static inline struct rtable *ovs_tunnel_route_lookup(struct net *net, | ||
| 240 | const struct ovs_key_ipv4_tunnel *key, | ||
| 241 | u32 mark, | ||
| 242 | struct flowi4 *fl, | ||
| 243 | u8 protocol) | ||
| 244 | { | ||
| 245 | struct rtable *rt; | ||
| 246 | |||
| 247 | memset(fl, 0, sizeof(*fl)); | ||
| 248 | fl->daddr = key->ipv4_dst; | ||
| 249 | fl->saddr = key->ipv4_src; | ||
| 250 | fl->flowi4_tos = RT_TOS(key->ipv4_tos); | ||
| 251 | fl->flowi4_mark = mark; | ||
| 252 | fl->flowi4_proto = protocol; | ||
| 253 | |||
| 254 | rt = ip_route_output_key(net, fl); | ||
| 255 | return rt; | ||
| 256 | } | ||
| 239 | #endif /* vport.h */ | 257 | #endif /* vport.h */ |
