Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Fan Du and committed by
David S. Miller
3f4c1d87 27331353

+25 -39
+2 -11
net/openvswitch/vport-geneve.c
··· 170 170 171 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 174 struct ovs_tunnel_info *tun_info; 175 175 struct net *net = ovs_dp_get_net(vport->dp); 176 176 struct geneve_port *geneve_port = geneve_vport(vport); ··· 189 189 } 190 190 191 191 tun_key = &tun_info->tunnel; 192 - 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); 192 + rt = ovs_tunnel_route_lookup(net, tun_key, skb->mark, &fl, IPPROTO_UDP); 202 193 if (IS_ERR(rt)) { 203 194 err = PTR_ERR(rt); 204 195 goto error;
+2 -10
net/openvswitch/vport-gre.c
··· 134 134 static int gre_tnl_send(struct vport *vport, struct sk_buff *skb) 135 135 { 136 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 138 struct flowi4 fl; 139 139 struct rtable *rt; 140 140 int min_headroom; ··· 148 148 } 149 149 150 150 tun_key = &OVS_CB(skb)->egress_tun_info->tunnel; 151 - /* Route lookup */ 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); 151 + rt = ovs_tunnel_route_lookup(net, tun_key, skb->mark, &fl, IPPROTO_GRE); 160 152 if (IS_ERR(rt)) { 161 153 err = PTR_ERR(rt); 162 154 goto err_free_skb;
+2 -10
net/openvswitch/vport-vxlan.c
··· 145 145 struct net *net = ovs_dp_get_net(vport->dp); 146 146 struct vxlan_port *vxlan_port = vxlan_vport(vport); 147 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 149 struct rtable *rt; 150 150 struct flowi4 fl; 151 151 __be16 src_port; ··· 158 158 } 159 159 160 160 tun_key = &OVS_CB(skb)->egress_tun_info->tunnel; 161 - /* Route lookup */ 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); 161 + rt = ovs_tunnel_route_lookup(net, tun_key, skb->mark, &fl, IPPROTO_UDP); 170 162 if (IS_ERR(rt)) { 171 163 err = PTR_ERR(rt); 172 164 goto error;
+1 -8
net/openvswitch/vport.c
··· 595 595 * The process may need to be changed if the corresponding process 596 596 * in vports ops changed. 597 597 */ 598 - memset(&fl, 0, sizeof(fl)); 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); 598 + rt = ovs_tunnel_route_lookup(net, tun_key, skb_mark, &fl, ipproto); 606 599 if (IS_ERR(rt)) 607 600 return PTR_ERR(rt); 608 601
+18
net/openvswitch/vport.h
··· 236 236 int ovs_vport_ops_register(struct vport_ops *ops); 237 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 257 #endif /* vport.h */