datapath.c (112d6212c80a1c560757520bd822a41c0ad15c2c) datapath.c (d4e4fdf9e4a27c87edb79b1478955075be141f67)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (c) 2007-2014 Nicira, Inc.
4 */
5
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7
8#include <linux/init.h>

--- 1867 unchanged lines hidden (view full) ---

1876 .mcgrps = &ovs_dp_datapath_multicast_group,
1877 .n_mcgrps = 1,
1878 .module = THIS_MODULE,
1879};
1880
1881/* Called with ovs_mutex or RCU read lock. */
1882static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,
1883 struct net *net, u32 portid, u32 seq,
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (c) 2007-2014 Nicira, Inc.
4 */
5
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7
8#include <linux/init.h>

--- 1867 unchanged lines hidden (view full) ---

1876 .mcgrps = &ovs_dp_datapath_multicast_group,
1877 .n_mcgrps = 1,
1878 .module = THIS_MODULE,
1879};
1880
1881/* Called with ovs_mutex or RCU read lock. */
1882static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,
1883 struct net *net, u32 portid, u32 seq,
1884 u32 flags, u8 cmd)
1884 u32 flags, u8 cmd, gfp_t gfp)
1885{
1886 struct ovs_header *ovs_header;
1887 struct ovs_vport_stats vport_stats;
1888 int err;
1889
1890 ovs_header = genlmsg_put(skb, portid, seq, &dp_vport_genl_family,
1891 flags, cmd);
1892 if (!ovs_header)

--- 4 unchanged lines hidden (view full) ---

1897 if (nla_put_u32(skb, OVS_VPORT_ATTR_PORT_NO, vport->port_no) ||
1898 nla_put_u32(skb, OVS_VPORT_ATTR_TYPE, vport->ops->type) ||
1899 nla_put_string(skb, OVS_VPORT_ATTR_NAME,
1900 ovs_vport_name(vport)) ||
1901 nla_put_u32(skb, OVS_VPORT_ATTR_IFINDEX, vport->dev->ifindex))
1902 goto nla_put_failure;
1903
1904 if (!net_eq(net, dev_net(vport->dev))) {
1885{
1886 struct ovs_header *ovs_header;
1887 struct ovs_vport_stats vport_stats;
1888 int err;
1889
1890 ovs_header = genlmsg_put(skb, portid, seq, &dp_vport_genl_family,
1891 flags, cmd);
1892 if (!ovs_header)

--- 4 unchanged lines hidden (view full) ---

1897 if (nla_put_u32(skb, OVS_VPORT_ATTR_PORT_NO, vport->port_no) ||
1898 nla_put_u32(skb, OVS_VPORT_ATTR_TYPE, vport->ops->type) ||
1899 nla_put_string(skb, OVS_VPORT_ATTR_NAME,
1900 ovs_vport_name(vport)) ||
1901 nla_put_u32(skb, OVS_VPORT_ATTR_IFINDEX, vport->dev->ifindex))
1902 goto nla_put_failure;
1903
1904 if (!net_eq(net, dev_net(vport->dev))) {
1905 int id = peernet2id_alloc(net, dev_net(vport->dev));
1905 int id = peernet2id_alloc(net, dev_net(vport->dev), gfp);
1906
1907 if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id))
1908 goto nla_put_failure;
1909 }
1910
1911 ovs_vport_get_stats(vport, &vport_stats);
1912 if (nla_put_64bit(skb, OVS_VPORT_ATTR_STATS,
1913 sizeof(struct ovs_vport_stats), &vport_stats,

--- 24 unchanged lines hidden (view full) ---

1938
1939/* Called with ovs_mutex, only via ovs_dp_notify_wq(). */
1940struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,
1941 u32 portid, u32 seq, u8 cmd)
1942{
1943 struct sk_buff *skb;
1944 int retval;
1945
1906
1907 if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id))
1908 goto nla_put_failure;
1909 }
1910
1911 ovs_vport_get_stats(vport, &vport_stats);
1912 if (nla_put_64bit(skb, OVS_VPORT_ATTR_STATS,
1913 sizeof(struct ovs_vport_stats), &vport_stats,

--- 24 unchanged lines hidden (view full) ---

1938
1939/* Called with ovs_mutex, only via ovs_dp_notify_wq(). */
1940struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,
1941 u32 portid, u32 seq, u8 cmd)
1942{
1943 struct sk_buff *skb;
1944 int retval;
1945
1946 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1946 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1947 if (!skb)
1948 return ERR_PTR(-ENOMEM);
1949
1947 if (!skb)
1948 return ERR_PTR(-ENOMEM);
1949
1950 retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd);
1950 retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd,
1951 GFP_KERNEL);
1951 BUG_ON(retval < 0);
1952
1953 return skb;
1954}
1955
1956/* Called with ovs_mutex or RCU read lock. */
1957static struct vport *lookup_vport(struct net *net,
1958 const struct ovs_header *ovs_header,

--- 125 unchanged lines hidden (view full) ---

2084 if (IS_ERR(vport)) {
2085 if (err == -EAGAIN)
2086 goto restart;
2087 goto exit_unlock_free;
2088 }
2089
2090 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2091 info->snd_portid, info->snd_seq, 0,
1952 BUG_ON(retval < 0);
1953
1954 return skb;
1955}
1956
1957/* Called with ovs_mutex or RCU read lock. */
1958static struct vport *lookup_vport(struct net *net,
1959 const struct ovs_header *ovs_header,

--- 125 unchanged lines hidden (view full) ---

2085 if (IS_ERR(vport)) {
2086 if (err == -EAGAIN)
2087 goto restart;
2088 goto exit_unlock_free;
2089 }
2090
2091 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2092 info->snd_portid, info->snd_seq, 0,
2092 OVS_VPORT_CMD_NEW);
2093 OVS_VPORT_CMD_NEW, GFP_KERNEL);
2093
2094 new_headroom = netdev_get_fwd_headroom(vport->dev);
2095
2096 if (new_headroom > dp->max_headroom)
2097 ovs_update_headroom(dp, new_headroom);
2098 else
2099 netdev_set_rx_headroom(vport->dev, dp->max_headroom);
2100

--- 44 unchanged lines hidden (view full) ---

2145
2146 err = ovs_vport_set_upcall_portids(vport, ids);
2147 if (err)
2148 goto exit_unlock_free;
2149 }
2150
2151 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2152 info->snd_portid, info->snd_seq, 0,
2094
2095 new_headroom = netdev_get_fwd_headroom(vport->dev);
2096
2097 if (new_headroom > dp->max_headroom)
2098 ovs_update_headroom(dp, new_headroom);
2099 else
2100 netdev_set_rx_headroom(vport->dev, dp->max_headroom);
2101

--- 44 unchanged lines hidden (view full) ---

2146
2147 err = ovs_vport_set_upcall_portids(vport, ids);
2148 if (err)
2149 goto exit_unlock_free;
2150 }
2151
2152 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2153 info->snd_portid, info->snd_seq, 0,
2153 OVS_VPORT_CMD_SET);
2154 OVS_VPORT_CMD_SET, GFP_KERNEL);
2154 BUG_ON(err < 0);
2155
2156 ovs_unlock();
2157 ovs_notify(&dp_vport_genl_family, reply, info);
2158 return 0;
2159
2160exit_unlock_free:
2161 ovs_unlock();

--- 23 unchanged lines hidden (view full) ---

2185
2186 if (vport->port_no == OVSP_LOCAL) {
2187 err = -EINVAL;
2188 goto exit_unlock_free;
2189 }
2190
2191 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2192 info->snd_portid, info->snd_seq, 0,
2155 BUG_ON(err < 0);
2156
2157 ovs_unlock();
2158 ovs_notify(&dp_vport_genl_family, reply, info);
2159 return 0;
2160
2161exit_unlock_free:
2162 ovs_unlock();

--- 23 unchanged lines hidden (view full) ---

2186
2187 if (vport->port_no == OVSP_LOCAL) {
2188 err = -EINVAL;
2189 goto exit_unlock_free;
2190 }
2191
2192 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2193 info->snd_portid, info->snd_seq, 0,
2193 OVS_VPORT_CMD_DEL);
2194 OVS_VPORT_CMD_DEL, GFP_KERNEL);
2194 BUG_ON(err < 0);
2195
2196 /* the vport deletion may trigger dp headroom update */
2197 dp = vport->dp;
2198 if (netdev_get_fwd_headroom(vport->dev) == dp->max_headroom)
2199 update_headroom = true;
2200
2201 netdev_reset_rx_headroom(vport->dev);

--- 30 unchanged lines hidden (view full) ---

2232
2233 rcu_read_lock();
2234 vport = lookup_vport(sock_net(skb->sk), ovs_header, a);
2235 err = PTR_ERR(vport);
2236 if (IS_ERR(vport))
2237 goto exit_unlock_free;
2238 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2239 info->snd_portid, info->snd_seq, 0,
2195 BUG_ON(err < 0);
2196
2197 /* the vport deletion may trigger dp headroom update */
2198 dp = vport->dp;
2199 if (netdev_get_fwd_headroom(vport->dev) == dp->max_headroom)
2200 update_headroom = true;
2201
2202 netdev_reset_rx_headroom(vport->dev);

--- 30 unchanged lines hidden (view full) ---

2233
2234 rcu_read_lock();
2235 vport = lookup_vport(sock_net(skb->sk), ovs_header, a);
2236 err = PTR_ERR(vport);
2237 if (IS_ERR(vport))
2238 goto exit_unlock_free;
2239 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2240 info->snd_portid, info->snd_seq, 0,
2240 OVS_VPORT_CMD_GET);
2241 OVS_VPORT_CMD_GET, GFP_ATOMIC);
2241 BUG_ON(err < 0);
2242 rcu_read_unlock();
2243
2244 return genlmsg_reply(reply, info);
2245
2246exit_unlock_free:
2247 rcu_read_unlock();
2248 kfree_skb(reply);

--- 19 unchanged lines hidden (view full) ---

2268 j = 0;
2269 hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) {
2270 if (j >= skip &&
2271 ovs_vport_cmd_fill_info(vport, skb,
2272 sock_net(skb->sk),
2273 NETLINK_CB(cb->skb).portid,
2274 cb->nlh->nlmsg_seq,
2275 NLM_F_MULTI,
2242 BUG_ON(err < 0);
2243 rcu_read_unlock();
2244
2245 return genlmsg_reply(reply, info);
2246
2247exit_unlock_free:
2248 rcu_read_unlock();
2249 kfree_skb(reply);

--- 19 unchanged lines hidden (view full) ---

2269 j = 0;
2270 hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) {
2271 if (j >= skip &&
2272 ovs_vport_cmd_fill_info(vport, skb,
2273 sock_net(skb->sk),
2274 NETLINK_CB(cb->skb).portid,
2275 cb->nlh->nlmsg_seq,
2276 NLM_F_MULTI,
2276 OVS_VPORT_CMD_GET) < 0)
2277 OVS_VPORT_CMD_GET,
2278 GFP_ATOMIC) < 0)
2277 goto out;
2278
2279 j++;
2280 }
2281 skip = 0;
2282 }
2283out:
2284 rcu_read_unlock();

--- 247 unchanged lines hidden ---
2279 goto out;
2280
2281 j++;
2282 }
2283 skip = 0;
2284 }
2285out:
2286 rcu_read_unlock();

--- 247 unchanged lines hidden ---