864 lines · 25.0 KB · C
RawDownload
 	switchdev = switchdev_lower_dev_find_rcu(br, check_cb, foreign_dev_check_cb);	if (!switchdev)		return 0; 	if (!foreign_dev_check_cb(switchdev, dev))		return err; 	return __switchdev_handle_fdb_event_to_device(br, orig_dev, event, fdb_info,						      check_cb, foreign_dev_check_cb,						      mod_cb);} int switchdev_handle_fdb_event_to_device(struct net_device *dev, unsigned long event,		const struct switchdev_notifier_fdb_info *fdb_info,		bool (*check_cb)(const struct net_device *dev),		bool (*foreign_dev_check_cb)(const struct net_device *dev,					     const struct net_device *foreign_dev),		int (*mod_cb)(struct net_device *dev, struct net_device *orig_dev,			      unsigned long event, const void *ctx,			      const struct switchdev_notifier_fdb_info *fdb_info)){	int err; 	err = __switchdev_handle_fdb_event_to_device(dev, dev, event, fdb_info,						     check_cb, foreign_dev_check_cb,						     mod_cb);	if (err == -EOPNOTSUPP)		err = 0; 	return err;}EXPORT_SYMBOL_GPL(switchdev_handle_fdb_event_to_device); static int __switchdev_handle_port_obj_add(struct net_device *dev,			struct switchdev_notifier_port_obj_info *port_obj_info,			bool (*check_cb)(const struct net_device *dev),			bool (*foreign_dev_check_cb)(const struct net_device *dev,						     const struct net_device *foreign_dev),			int (*add_cb)(struct net_device *dev, const void *ctx,				      const struct switchdev_obj *obj,				      struct netlink_ext_ack *extack)){	struct switchdev_notifier_info *info = &port_obj_info->info;	struct net_device *br, *lower_dev, *switchdev;	struct netlink_ext_ack *extack;	struct list_head *iter;	int err = -EOPNOTSUPP; 	extack = switchdev_notifier_info_to_extack(info); 	if (check_cb(dev)) {		err = add_cb(dev, info->ctx, port_obj_info->obj, extack);		if (err != -EOPNOTSUPP)			port_obj_info->handled = true;		return err;	} 	/* Switch ports might be stacked under e.g. a LAG. Ignore the	 * unsupported devices, another driver might be able to handle them. But	 * propagate to the callers any hard errors.	 *	 * If the driver does its own bookkeeping of stacked ports, it's not	 * necessary to go through this helper.	 */	netdev_for_each_lower_dev(dev, lower_dev, iter) {		if (netif_is_bridge_master(lower_dev))			continue; 		/* When searching for switchdev interfaces that are neighbors		 * of foreign ones, and @dev is a bridge, do not recurse on the		 * foreign interface again, it was already visited.		 */		if (foreign_dev_check_cb && !check_cb(lower_dev) &&		    !switchdev_lower_dev_find(lower_dev, check_cb, foreign_dev_check_cb))			continue; 		err = __switchdev_handle_port_obj_add(lower_dev, port_obj_info,						      check_cb, foreign_dev_check_cb,						      add_cb);		if (err && err != -EOPNOTSUPP)			return err;	} 	/* Event is neither on a bridge nor a LAG. Check whether it is on an	 * interface that is in a bridge with us.	 */	if (!foreign_dev_check_cb)		return err; 	br = netdev_master_upper_dev_get(dev);	if (!br || !netif_is_bridge_master(br))		return err; 	switchdev = switchdev_lower_dev_find(br, check_cb, foreign_dev_check_cb);	if (!switchdev)		return err; 	if (!foreign_dev_check_cb(switchdev, dev))		return err; 	return __switchdev_handle_port_obj_add(br, port_obj_info, check_cb,					       foreign_dev_check_cb, add_cb);} /* Pass through a port object addition, if @dev passes @check_cb, or replicate * it towards all lower interfaces of @dev that pass @check_cb, if @dev is a * bridge or a LAG. */int switchdev_handle_port_obj_add(struct net_device *dev,			struct switchdev_notifier_port_obj_info *port_obj_info,			bool (*check_cb)(const struct net_device *dev),			int (*add_cb)(struct net_device *dev, const void *ctx,				      const struct switchdev_obj *obj,				      struct netlink_ext_ack *extack)){	int err; 	err = __switchdev_handle_port_obj_add(dev, port_obj_info, check_cb,					      NULL, add_cb);	if (err == -EOPNOTSUPP)		err = 0;	return err;}EXPORT_SYMBOL_GPL(switchdev_handle_port_obj_add); /* Same as switchdev_handle_port_obj_add(), except if object is notified on a * @dev that passes @foreign_dev_check_cb, it is replicated towards all devices * that pass @check_cb and are in the same bridge as @dev. */int switchdev_handle_port_obj_add_foreign(struct net_device *dev,			struct switchdev_notifier_port_obj_info *port_obj_info,			bool (*check_cb)(const struct net_device *dev),			bool (*foreign_dev_check_cb)(const struct net_device *dev,						     const struct net_device *foreign_dev),			int (*add_cb)(struct net_device *dev, const void *ctx,				      const struct switchdev_obj *obj,				      struct netlink_ext_ack *extack)){	int err; 	err = __switchdev_handle_port_obj_add(dev, port_obj_info, check_cb,					      foreign_dev_check_cb, add_cb);	if (err == -EOPNOTSUPP)		err = 0;	return err;}EXPORT_SYMBOL_GPL(switchdev_handle_port_obj_add_foreign); static int __switchdev_handle_port_obj_del(struct net_device *dev,			struct switchdev_notifier_port_obj_info *port_obj_info,			bool (*check_cb)(const struct net_device *dev),			bool (*foreign_dev_check_cb)(const struct net_device *dev,						     const struct net_device *foreign_dev),			int (*del_cb)(struct net_device *dev, const void *ctx,				      const struct switchdev_obj *obj)){	struct switchdev_notifier_info *info = &port_obj_info->info;	struct net_device *br, *lower_dev, *switchdev;	struct list_head *iter;	int err = -EOPNOTSUPP; 	if (check_cb(dev)) {		err = del_cb(dev, info->ctx, port_obj_info->obj);		if (err != -EOPNOTSUPP)			port_obj_info->handled = true;		return err;	} 	/* Switch ports might be stacked under e.g. a LAG. Ignore the	 * unsupported devices, another driver might be able to handle them. But	 * propagate to the callers any hard errors.	 *	 * If the driver does its own bookkeeping of stacked ports, it's not	 * necessary to go through this helper.	 */	netdev_for_each_lower_dev(dev, lower_dev, iter) {		if (netif_is_bridge_master(lower_dev))			continue; 		/* When searching for switchdev interfaces that are neighbors		 * of foreign ones, and @dev is a bridge, do not recurse on the		 * foreign interface again, it was already visited.		 */		if (foreign_dev_check_cb && !check_cb(lower_dev) &&		    !switchdev_lower_dev_find(lower_dev, check_cb, foreign_dev_check_cb))			continue; 		err = __switchdev_handle_port_obj_del(lower_dev, port_obj_info,						      check_cb, foreign_dev_check_cb,						      del_cb);		if (err && err != -EOPNOTSUPP)			return err;	} 	/* Event is neither on a bridge nor a LAG. Check whether it is on an	 * interface that is in a bridge with us.	 */	if (!foreign_dev_check_cb)		return err; 	br = netdev_master_upper_dev_get(dev);	if (!br || !netif_is_bridge_master(br))		return err; 	switchdev = switchdev_lower_dev_find(br, check_cb, foreign_dev_check_cb);	if (!switchdev)		return err; 	if (!foreign_dev_check_cb(switchdev, dev))		return err; 	return __switchdev_handle_port_obj_del(br, port_obj_info, check_cb,					       foreign_dev_check_cb, del_cb);} /* Pass through a port object deletion, if @dev passes @check_cb, or replicate * it towards all lower interfaces of @dev that pass @check_cb, if @dev is a * bridge or a LAG. */int switchdev_handle_port_obj_del(struct net_device *dev,			struct switchdev_notifier_port_obj_info *port_obj_info,			bool (*check_cb)(const struct net_device *dev),			int (*del_cb)(struct net_device *dev, const void *ctx,				      const struct switchdev_obj *obj)){	int err; 	err = __switchdev_handle_port_obj_del(dev, port_obj_info, check_cb,					      NULL, del_cb);	if (err == -EOPNOTSUPP)		err = 0;	return err;}EXPORT_SYMBOL_GPL(switchdev_handle_port_obj_del); /* Same as switchdev_handle_port_obj_del(), except if object is notified on a * @dev that passes @foreign_dev_check_cb, it is replicated towards all devices * that pass @check_cb and are in the same bridge as @dev. */int switchdev_handle_port_obj_del_foreign(struct net_device *dev,			struct switchdev_notifier_port_obj_info *port_obj_info,			bool (*check_cb)(const struct net_device *dev),			bool (*foreign_dev_check_cb)(const struct net_device *dev,						     const struct net_device *foreign_dev),			int (*del_cb)(struct net_device *dev, const void *ctx,				      const struct switchdev_obj *obj)){	int err; 	err = __switchdev_handle_port_obj_del(dev, port_obj_info, check_cb,					      foreign_dev_check_cb, del_cb);	if (err == -EOPNOTSUPP)		err = 0;	return err;}EXPORT_SYMBOL_GPL(switchdev_handle_port_obj_del_foreign); static int __switchdev_handle_port_attr_set(struct net_device *dev,			struct switchdev_notifier_port_attr_info *port_attr_info,			bool (*check_cb)(const struct net_device *dev),			int (*set_cb)(struct net_device *dev, const void *ctx,				      const struct switchdev_attr *attr,				      struct netlink_ext_ack *extack)){	struct switchdev_notifier_info *info = &port_attr_info->info;	struct netlink_ext_ack *extack;	struct net_device *lower_dev;	struct list_head *iter;	int err = -EOPNOTSUPP; 	extack = switchdev_notifier_info_to_extack(info); 	if (check_cb(dev)) {		err = set_cb(dev, info->ctx, port_attr_info->attr, extack);		if (err != -EOPNOTSUPP)			port_attr_info->handled = true;		return err;	} 	/* Switch ports might be stacked under e.g. a LAG. Ignore the	 * unsupported devices, another driver might be able to handle them. But	 * propagate to the callers any hard errors.	 *	 * If the driver does its own bookkeeping of stacked ports, it's not	 * necessary to go through this helper.	 */	netdev_for_each_lower_dev(dev, lower_dev, iter) {		if (netif_is_bridge_master(lower_dev))			continue; 		err = __switchdev_handle_port_attr_set(lower_dev, port_attr_info,						       check_cb, set_cb);		if (err && err != -EOPNOTSUPP)			return err;	} 	return err;} int switchdev_handle_port_attr_set(struct net_device *dev,			struct switchdev_notifier_port_attr_info *port_attr_info,			bool (*check_cb)(const struct net_device *dev),			int (*set_cb)(struct net_device *dev, const void *ctx,				      const struct switchdev_attr *attr,				      struct netlink_ext_ack *extack)){	int err; 	err = __switchdev_handle_port_attr_set(dev, port_attr_info, check_cb,					       set_cb);	if (err == -EOPNOTSUPP)		err = 0;	return err;}EXPORT_SYMBOL_GPL(switchdev_handle_port_attr_set); int switchdev_bridge_port_offload(struct net_device *brport_dev,				  struct net_device *dev, const void *ctx,				  struct notifier_block *atomic_nb,				  struct notifier_block *blocking_nb,				  bool tx_fwd_offload,				  struct netlink_ext_ack *extack){	struct switchdev_notifier_brport_info brport_info = {		.brport = {			.dev = dev,			.ctx = ctx,			.atomic_nb = atomic_nb,			.blocking_nb = blocking_nb,			.tx_fwd_offload = tx_fwd_offload,		},	};	int err; 	ASSERT_RTNL(); 	err = call_switchdev_blocking_notifiers(SWITCHDEV_BRPORT_OFFLOADED,						brport_dev, &brport_info.info,						extack);	return notifier_to_errno(err);}EXPORT_SYMBOL_GPL(switchdev_bridge_port_offload); void switchdev_bridge_port_unoffload(struct net_device *brport_dev,				     const void *ctx,				     struct notifier_block *atomic_nb,				     struct notifier_block *blocking_nb){	struct switchdev_notifier_brport_info brport_info = {		.brport = {			.ctx = ctx,			.atomic_nb = atomic_nb,			.blocking_nb = blocking_nb,		},	}; 	ASSERT_RTNL(); 	call_switchdev_blocking_notifiers(SWITCHDEV_BRPORT_UNOFFLOADED,					  brport_dev, &brport_info.info,					  NULL);}EXPORT_SYMBOL_GPL(switchdev_bridge_port_unoffload);

Lines 501–864 of 864. Previous lines