flow.c (74f84a5726c7d08c27745305e67474b8645c541d) | flow.c (7d5437c709ded4f152cb8b305d17972d6707f20c) |
---|---|
1/* 2 * Copyright (c) 2007-2011 Nicira, Inc. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of version 2 of the GNU General Public 6 * License as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but --- 26 unchanged lines hidden (view full) --- 35#include <linux/ip.h> 36#include <linux/ipv6.h> 37#include <linux/tcp.h> 38#include <linux/udp.h> 39#include <linux/icmp.h> 40#include <linux/icmpv6.h> 41#include <linux/rculist.h> 42#include <net/ip.h> | 1/* 2 * Copyright (c) 2007-2011 Nicira, Inc. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of version 2 of the GNU General Public 6 * License as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but --- 26 unchanged lines hidden (view full) --- 35#include <linux/ip.h> 36#include <linux/ipv6.h> 37#include <linux/tcp.h> 38#include <linux/udp.h> 39#include <linux/icmp.h> 40#include <linux/icmpv6.h> 41#include <linux/rculist.h> 42#include <net/ip.h> |
43#include <net/ip_tunnels.h> |
|
43#include <net/ipv6.h> 44#include <net/ndisc.h> 45 46static struct kmem_cache *flow_cache; 47 48static int check_header(struct sk_buff *skb, int len) 49{ 50 if (unlikely(skb->len < len)) --- 547 unchanged lines hidden (view full) --- 598{ 599 int error = 0; 600 int key_len = SW_FLOW_KEY_OFFSET(eth); 601 struct ethhdr *eth; 602 603 memset(key, 0, sizeof(*key)); 604 605 key->phy.priority = skb->priority; | 44#include <net/ipv6.h> 45#include <net/ndisc.h> 46 47static struct kmem_cache *flow_cache; 48 49static int check_header(struct sk_buff *skb, int len) 50{ 51 if (unlikely(skb->len < len)) --- 547 unchanged lines hidden (view full) --- 599{ 600 int error = 0; 601 int key_len = SW_FLOW_KEY_OFFSET(eth); 602 struct ethhdr *eth; 603 604 memset(key, 0, sizeof(*key)); 605 606 key->phy.priority = skb->priority; |
607 if (OVS_CB(skb)->tun_key) 608 memcpy(&key->tun_key, OVS_CB(skb)->tun_key, sizeof(key->tun_key)); |
|
606 key->phy.in_port = in_port; 607 key->phy.skb_mark = skb->mark; 608 609 skb_reset_mac_header(skb); 610 611 /* Link layer. We are guaranteed to have at least the 14 byte Ethernet 612 * header in the linear data area. 613 */ --- 199 unchanged lines hidden (view full) --- 813 [OVS_KEY_ATTR_IPV4] = sizeof(struct ovs_key_ipv4), 814 [OVS_KEY_ATTR_IPV6] = sizeof(struct ovs_key_ipv6), 815 [OVS_KEY_ATTR_TCP] = sizeof(struct ovs_key_tcp), 816 [OVS_KEY_ATTR_UDP] = sizeof(struct ovs_key_udp), 817 [OVS_KEY_ATTR_ICMP] = sizeof(struct ovs_key_icmp), 818 [OVS_KEY_ATTR_ICMPV6] = sizeof(struct ovs_key_icmpv6), 819 [OVS_KEY_ATTR_ARP] = sizeof(struct ovs_key_arp), 820 [OVS_KEY_ATTR_ND] = sizeof(struct ovs_key_nd), | 609 key->phy.in_port = in_port; 610 key->phy.skb_mark = skb->mark; 611 612 skb_reset_mac_header(skb); 613 614 /* Link layer. We are guaranteed to have at least the 14 byte Ethernet 615 * header in the linear data area. 616 */ --- 199 unchanged lines hidden (view full) --- 816 [OVS_KEY_ATTR_IPV4] = sizeof(struct ovs_key_ipv4), 817 [OVS_KEY_ATTR_IPV6] = sizeof(struct ovs_key_ipv6), 818 [OVS_KEY_ATTR_TCP] = sizeof(struct ovs_key_tcp), 819 [OVS_KEY_ATTR_UDP] = sizeof(struct ovs_key_udp), 820 [OVS_KEY_ATTR_ICMP] = sizeof(struct ovs_key_icmp), 821 [OVS_KEY_ATTR_ICMPV6] = sizeof(struct ovs_key_icmpv6), 822 [OVS_KEY_ATTR_ARP] = sizeof(struct ovs_key_arp), 823 [OVS_KEY_ATTR_ND] = sizeof(struct ovs_key_nd), |
824 [OVS_KEY_ATTR_TUNNEL] = -1, |
|
821}; 822 823static int ipv4_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_len, 824 const struct nlattr *a[], u32 *attrs) 825{ 826 const struct ovs_key_icmp *icmp_key; 827 const struct ovs_key_tcp *tcp_key; 828 const struct ovs_key_udp *udp_key; --- 121 unchanged lines hidden (view full) --- 950 } 951 if (rem) 952 return -EINVAL; 953 954 *attrsp = attrs; 955 return 0; 956} 957 | 825}; 826 827static int ipv4_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_len, 828 const struct nlattr *a[], u32 *attrs) 829{ 830 const struct ovs_key_icmp *icmp_key; 831 const struct ovs_key_tcp *tcp_key; 832 const struct ovs_key_udp *udp_key; --- 121 unchanged lines hidden (view full) --- 954 } 955 if (rem) 956 return -EINVAL; 957 958 *attrsp = attrs; 959 return 0; 960} 961 |
962int ovs_ipv4_tun_from_nlattr(const struct nlattr *attr, 963 struct ovs_key_ipv4_tunnel *tun_key) 964{ 965 struct nlattr *a; 966 int rem; 967 bool ttl = false; 968 969 memset(tun_key, 0, sizeof(*tun_key)); 970 971 nla_for_each_nested(a, attr, rem) { 972 int type = nla_type(a); 973 static const u32 ovs_tunnel_key_lens[OVS_TUNNEL_KEY_ATTR_MAX + 1] = { 974 [OVS_TUNNEL_KEY_ATTR_ID] = sizeof(u64), 975 [OVS_TUNNEL_KEY_ATTR_IPV4_SRC] = sizeof(u32), 976 [OVS_TUNNEL_KEY_ATTR_IPV4_DST] = sizeof(u32), 977 [OVS_TUNNEL_KEY_ATTR_TOS] = 1, 978 [OVS_TUNNEL_KEY_ATTR_TTL] = 1, 979 [OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT] = 0, 980 [OVS_TUNNEL_KEY_ATTR_CSUM] = 0, 981 }; 982 983 if (type > OVS_TUNNEL_KEY_ATTR_MAX || 984 ovs_tunnel_key_lens[type] != nla_len(a)) 985 return -EINVAL; 986 987 switch (type) { 988 case OVS_TUNNEL_KEY_ATTR_ID: 989 tun_key->tun_id = nla_get_be64(a); 990 tun_key->tun_flags |= TUNNEL_KEY; 991 break; 992 case OVS_TUNNEL_KEY_ATTR_IPV4_SRC: 993 tun_key->ipv4_src = nla_get_be32(a); 994 break; 995 case OVS_TUNNEL_KEY_ATTR_IPV4_DST: 996 tun_key->ipv4_dst = nla_get_be32(a); 997 break; 998 case OVS_TUNNEL_KEY_ATTR_TOS: 999 tun_key->ipv4_tos = nla_get_u8(a); 1000 break; 1001 case OVS_TUNNEL_KEY_ATTR_TTL: 1002 tun_key->ipv4_ttl = nla_get_u8(a); 1003 ttl = true; 1004 break; 1005 case OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT: 1006 tun_key->tun_flags |= TUNNEL_DONT_FRAGMENT; 1007 break; 1008 case OVS_TUNNEL_KEY_ATTR_CSUM: 1009 tun_key->tun_flags |= TUNNEL_CSUM; 1010 break; 1011 default: 1012 return -EINVAL; 1013 1014 } 1015 } 1016 if (rem > 0) 1017 return -EINVAL; 1018 1019 if (!tun_key->ipv4_dst) 1020 return -EINVAL; 1021 1022 if (!ttl) 1023 return -EINVAL; 1024 1025 return 0; 1026} 1027 1028int ovs_ipv4_tun_to_nlattr(struct sk_buff *skb, 1029 const struct ovs_key_ipv4_tunnel *tun_key) 1030{ 1031 struct nlattr *nla; 1032 1033 nla = nla_nest_start(skb, OVS_KEY_ATTR_TUNNEL); 1034 if (!nla) 1035 return -EMSGSIZE; 1036 1037 if (tun_key->tun_flags & TUNNEL_KEY && 1038 nla_put_be64(skb, OVS_TUNNEL_KEY_ATTR_ID, tun_key->tun_id)) 1039 return -EMSGSIZE; 1040 if (tun_key->ipv4_src && 1041 nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_IPV4_SRC, tun_key->ipv4_src)) 1042 return -EMSGSIZE; 1043 if (nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_IPV4_DST, tun_key->ipv4_dst)) 1044 return -EMSGSIZE; 1045 if (tun_key->ipv4_tos && 1046 nla_put_u8(skb, OVS_TUNNEL_KEY_ATTR_TOS, tun_key->ipv4_tos)) 1047 return -EMSGSIZE; 1048 if (nla_put_u8(skb, OVS_TUNNEL_KEY_ATTR_TTL, tun_key->ipv4_ttl)) 1049 return -EMSGSIZE; 1050 if ((tun_key->tun_flags & TUNNEL_DONT_FRAGMENT) && 1051 nla_put_flag(skb, OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT)) 1052 return -EMSGSIZE; 1053 if ((tun_key->tun_flags & TUNNEL_CSUM) && 1054 nla_put_flag(skb, OVS_TUNNEL_KEY_ATTR_CSUM)) 1055 return -EMSGSIZE; 1056 1057 nla_nest_end(skb, nla); 1058 return 0; 1059} 1060 |
|
958/** 959 * ovs_flow_from_nlattrs - parses Netlink attributes into a flow key. 960 * @swkey: receives the extracted flow key. 961 * @key_lenp: number of bytes used in @swkey. 962 * @attr: Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink attribute 963 * sequence. 964 */ 965int ovs_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp, --- 26 unchanged lines hidden (view full) --- 992 } else { 993 swkey->phy.in_port = DP_MAX_PORTS; 994 } 995 if (attrs & (1 << OVS_KEY_ATTR_SKB_MARK)) { 996 swkey->phy.skb_mark = nla_get_u32(a[OVS_KEY_ATTR_SKB_MARK]); 997 attrs &= ~(1 << OVS_KEY_ATTR_SKB_MARK); 998 } 999 | 1061/** 1062 * ovs_flow_from_nlattrs - parses Netlink attributes into a flow key. 1063 * @swkey: receives the extracted flow key. 1064 * @key_lenp: number of bytes used in @swkey. 1065 * @attr: Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink attribute 1066 * sequence. 1067 */ 1068int ovs_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp, --- 26 unchanged lines hidden (view full) --- 1095 } else { 1096 swkey->phy.in_port = DP_MAX_PORTS; 1097 } 1098 if (attrs & (1 << OVS_KEY_ATTR_SKB_MARK)) { 1099 swkey->phy.skb_mark = nla_get_u32(a[OVS_KEY_ATTR_SKB_MARK]); 1100 attrs &= ~(1 << OVS_KEY_ATTR_SKB_MARK); 1101 } 1102 |
1103 if (attrs & (1 << OVS_KEY_ATTR_TUNNEL)) { 1104 err = ovs_ipv4_tun_from_nlattr(a[OVS_KEY_ATTR_TUNNEL], &swkey->tun_key); 1105 if (err) 1106 return err; 1107 1108 attrs &= ~(1 << OVS_KEY_ATTR_TUNNEL); 1109 } 1110 |
|
1000 /* Data attributes. */ 1001 if (!(attrs & (1 << OVS_KEY_ATTR_ETHERNET))) 1002 return -EINVAL; 1003 attrs &= ~(1 << OVS_KEY_ATTR_ETHERNET); 1004 1005 eth_key = nla_data(a[OVS_KEY_ATTR_ETHERNET]); 1006 memcpy(swkey->eth.src, eth_key->eth_src, ETH_ALEN); 1007 memcpy(swkey->eth.dst, eth_key->eth_dst, ETH_ALEN); --- 122 unchanged lines hidden (view full) --- 1130 * This parses a series of Netlink attributes that form a flow key, which must 1131 * take the same form accepted by flow_from_nlattrs(), but only enough of it to 1132 * get the metadata, that is, the parts of the flow key that cannot be 1133 * extracted from the packet itself. 1134 */ 1135int ovs_flow_metadata_from_nlattrs(struct sw_flow *flow, 1136 const struct nlattr *attr) 1137{ | 1111 /* Data attributes. */ 1112 if (!(attrs & (1 << OVS_KEY_ATTR_ETHERNET))) 1113 return -EINVAL; 1114 attrs &= ~(1 << OVS_KEY_ATTR_ETHERNET); 1115 1116 eth_key = nla_data(a[OVS_KEY_ATTR_ETHERNET]); 1117 memcpy(swkey->eth.src, eth_key->eth_src, ETH_ALEN); 1118 memcpy(swkey->eth.dst, eth_key->eth_dst, ETH_ALEN); --- 122 unchanged lines hidden (view full) --- 1241 * This parses a series of Netlink attributes that form a flow key, which must 1242 * take the same form accepted by flow_from_nlattrs(), but only enough of it to 1243 * get the metadata, that is, the parts of the flow key that cannot be 1244 * extracted from the packet itself. 1245 */ 1246int ovs_flow_metadata_from_nlattrs(struct sw_flow *flow, 1247 const struct nlattr *attr) 1248{ |
1249 struct ovs_key_ipv4_tunnel *tun_key = &flow->key.tun_key; |
|
1138 const struct nlattr *nla; 1139 int rem; 1140 1141 flow->key.phy.in_port = DP_MAX_PORTS; 1142 flow->key.phy.priority = 0; 1143 flow->key.phy.skb_mark = 0; | 1250 const struct nlattr *nla; 1251 int rem; 1252 1253 flow->key.phy.in_port = DP_MAX_PORTS; 1254 flow->key.phy.priority = 0; 1255 flow->key.phy.skb_mark = 0; |
1256 memset(tun_key, 0, sizeof(flow->key.tun_key)); |
|
1144 1145 nla_for_each_nested(nla, attr, rem) { 1146 int type = nla_type(nla); 1147 1148 if (type <= OVS_KEY_ATTR_MAX && ovs_key_lens[type] > 0) { | 1257 1258 nla_for_each_nested(nla, attr, rem) { 1259 int type = nla_type(nla); 1260 1261 if (type <= OVS_KEY_ATTR_MAX && ovs_key_lens[type] > 0) { |
1262 int err; 1263 |
|
1149 if (nla_len(nla) != ovs_key_lens[type]) 1150 return -EINVAL; 1151 1152 switch (type) { 1153 case OVS_KEY_ATTR_PRIORITY: 1154 flow->key.phy.priority = nla_get_u32(nla); 1155 break; 1156 | 1264 if (nla_len(nla) != ovs_key_lens[type]) 1265 return -EINVAL; 1266 1267 switch (type) { 1268 case OVS_KEY_ATTR_PRIORITY: 1269 flow->key.phy.priority = nla_get_u32(nla); 1270 break; 1271 |
1272 case OVS_KEY_ATTR_TUNNEL: 1273 err = ovs_ipv4_tun_from_nlattr(nla, tun_key); 1274 if (err) 1275 return err; 1276 break; 1277 |
|
1157 case OVS_KEY_ATTR_IN_PORT: 1158 if (nla_get_u32(nla) >= DP_MAX_PORTS) 1159 return -EINVAL; 1160 flow->key.phy.in_port = nla_get_u32(nla); 1161 break; 1162 1163 case OVS_KEY_ATTR_SKB_MARK: 1164 flow->key.phy.skb_mark = nla_get_u32(nla); --- 10 unchanged lines hidden (view full) --- 1175{ 1176 struct ovs_key_ethernet *eth_key; 1177 struct nlattr *nla, *encap; 1178 1179 if (swkey->phy.priority && 1180 nla_put_u32(skb, OVS_KEY_ATTR_PRIORITY, swkey->phy.priority)) 1181 goto nla_put_failure; 1182 | 1278 case OVS_KEY_ATTR_IN_PORT: 1279 if (nla_get_u32(nla) >= DP_MAX_PORTS) 1280 return -EINVAL; 1281 flow->key.phy.in_port = nla_get_u32(nla); 1282 break; 1283 1284 case OVS_KEY_ATTR_SKB_MARK: 1285 flow->key.phy.skb_mark = nla_get_u32(nla); --- 10 unchanged lines hidden (view full) --- 1296{ 1297 struct ovs_key_ethernet *eth_key; 1298 struct nlattr *nla, *encap; 1299 1300 if (swkey->phy.priority && 1301 nla_put_u32(skb, OVS_KEY_ATTR_PRIORITY, swkey->phy.priority)) 1302 goto nla_put_failure; 1303 |
1304 if (swkey->tun_key.ipv4_dst && 1305 ovs_ipv4_tun_to_nlattr(skb, &swkey->tun_key)) 1306 goto nla_put_failure; 1307 |
|
1183 if (swkey->phy.in_port != DP_MAX_PORTS && 1184 nla_put_u32(skb, OVS_KEY_ATTR_IN_PORT, swkey->phy.in_port)) 1185 goto nla_put_failure; 1186 1187 if (swkey->phy.skb_mark && 1188 nla_put_u32(skb, OVS_KEY_ATTR_SKB_MARK, swkey->phy.skb_mark)) 1189 goto nla_put_failure; 1190 --- 166 unchanged lines hidden --- | 1308 if (swkey->phy.in_port != DP_MAX_PORTS && 1309 nla_put_u32(skb, OVS_KEY_ATTR_IN_PORT, swkey->phy.in_port)) 1310 goto nla_put_failure; 1311 1312 if (swkey->phy.skb_mark && 1313 nla_put_u32(skb, OVS_KEY_ATTR_SKB_MARK, swkey->phy.skb_mark)) 1314 goto nla_put_failure; 1315 --- 166 unchanged lines hidden --- |