Linux Audio

Check our new training course

Loading...
v3.15
 
  1/*
  2 * drivers/net/team/team_mode_loadbalance.c - Load-balancing mode for team
  3 * Copyright (c) 2012 Jiri Pirko <jpirko@redhat.com>
  4 *
  5 * This program is free software; you can redistribute it and/or modify
  6 * it under the terms of the GNU General Public License as published by
  7 * the Free Software Foundation; either version 2 of the License, or
  8 * (at your option) any later version.
  9 */
 10
 11#include <linux/kernel.h>
 12#include <linux/types.h>
 13#include <linux/module.h>
 14#include <linux/init.h>
 15#include <linux/errno.h>
 16#include <linux/netdevice.h>
 
 17#include <linux/filter.h>
 18#include <linux/if_team.h>
 19
 
 
 
 
 
 
 
 
 
 
 
 
 
 20struct lb_priv;
 21
 22typedef struct team_port *lb_select_tx_port_func_t(struct team *,
 23						   struct lb_priv *,
 24						   struct sk_buff *,
 25						   unsigned char);
 26
 27#define LB_TX_HASHTABLE_SIZE 256 /* hash is a char */
 28
 29struct lb_stats {
 30	u64 tx_bytes;
 31};
 32
 33struct lb_pcpu_stats {
 34	struct lb_stats hash_stats[LB_TX_HASHTABLE_SIZE];
 35	struct u64_stats_sync syncp;
 36};
 37
 38struct lb_stats_info {
 39	struct lb_stats stats;
 40	struct lb_stats last_stats;
 41	struct team_option_inst_info *opt_inst_info;
 42};
 43
 44struct lb_port_mapping {
 45	struct team_port __rcu *port;
 46	struct team_option_inst_info *opt_inst_info;
 47};
 48
 49struct lb_priv_ex {
 50	struct team *team;
 51	struct lb_port_mapping tx_hash_to_port_mapping[LB_TX_HASHTABLE_SIZE];
 52	struct sock_fprog *orig_fprog;
 53	struct {
 54		unsigned int refresh_interval; /* in tenths of second */
 55		struct delayed_work refresh_dw;
 56		struct lb_stats_info info[LB_TX_HASHTABLE_SIZE];
 57	} stats;
 58};
 59
 60struct lb_priv {
 61	struct sk_filter __rcu *fp;
 62	lb_select_tx_port_func_t __rcu *select_tx_port_func;
 63	struct lb_pcpu_stats __percpu *pcpu_stats;
 64	struct lb_priv_ex *ex; /* priv extension */
 65};
 66
 67static struct lb_priv *get_lb_priv(struct team *team)
 68{
 69	return (struct lb_priv *) &team->mode_priv;
 70}
 71
 72struct lb_port_priv {
 73	struct lb_stats __percpu *pcpu_stats;
 74	struct lb_stats_info stats_info;
 75};
 76
 77static struct lb_port_priv *get_lb_port_priv(struct team_port *port)
 78{
 79	return (struct lb_port_priv *) &port->mode_priv;
 80}
 81
 82#define LB_HTPM_PORT_BY_HASH(lp_priv, hash) \
 83	(lb_priv)->ex->tx_hash_to_port_mapping[hash].port
 84
 85#define LB_HTPM_OPT_INST_INFO_BY_HASH(lp_priv, hash) \
 86	(lb_priv)->ex->tx_hash_to_port_mapping[hash].opt_inst_info
 87
 88static void lb_tx_hash_to_port_mapping_null_port(struct team *team,
 89						 struct team_port *port)
 90{
 91	struct lb_priv *lb_priv = get_lb_priv(team);
 92	bool changed = false;
 93	int i;
 94
 95	for (i = 0; i < LB_TX_HASHTABLE_SIZE; i++) {
 96		struct lb_port_mapping *pm;
 97
 98		pm = &lb_priv->ex->tx_hash_to_port_mapping[i];
 99		if (rcu_access_pointer(pm->port) == port) {
100			RCU_INIT_POINTER(pm->port, NULL);
101			team_option_inst_set_change(pm->opt_inst_info);
102			changed = true;
103		}
104	}
105	if (changed)
106		team_options_change_check(team);
107}
108
109/* Basic tx selection based solely by hash */
110static struct team_port *lb_hash_select_tx_port(struct team *team,
111						struct lb_priv *lb_priv,
112						struct sk_buff *skb,
113						unsigned char hash)
114{
115	int port_index = team_num_to_port_index(team, hash);
116
117	return team_get_port_by_index_rcu(team, port_index);
118}
119
120/* Hash to port mapping select tx port */
121static struct team_port *lb_htpm_select_tx_port(struct team *team,
122						struct lb_priv *lb_priv,
123						struct sk_buff *skb,
124						unsigned char hash)
125{
126	return rcu_dereference_bh(LB_HTPM_PORT_BY_HASH(lb_priv, hash));
 
 
 
 
 
 
 
127}
128
129struct lb_select_tx_port {
130	char *name;
131	lb_select_tx_port_func_t *func;
132};
133
134static const struct lb_select_tx_port lb_select_tx_port_list[] = {
135	{
136		.name = "hash",
137		.func = lb_hash_select_tx_port,
138	},
139	{
140		.name = "hash_to_port_mapping",
141		.func = lb_htpm_select_tx_port,
142	},
143};
144#define LB_SELECT_TX_PORT_LIST_COUNT ARRAY_SIZE(lb_select_tx_port_list)
145
146static char *lb_select_tx_port_get_name(lb_select_tx_port_func_t *func)
147{
148	int i;
149
150	for (i = 0; i < LB_SELECT_TX_PORT_LIST_COUNT; i++) {
151		const struct lb_select_tx_port *item;
152
153		item = &lb_select_tx_port_list[i];
154		if (item->func == func)
155			return item->name;
156	}
157	return NULL;
158}
159
160static lb_select_tx_port_func_t *lb_select_tx_port_get_func(const char *name)
161{
162	int i;
163
164	for (i = 0; i < LB_SELECT_TX_PORT_LIST_COUNT; i++) {
165		const struct lb_select_tx_port *item;
166
167		item = &lb_select_tx_port_list[i];
168		if (!strcmp(item->name, name))
169			return item->func;
170	}
171	return NULL;
172}
173
174static unsigned int lb_get_skb_hash(struct lb_priv *lb_priv,
175				    struct sk_buff *skb)
176{
177	struct sk_filter *fp;
178	uint32_t lhash;
179	unsigned char *c;
180
181	fp = rcu_dereference_bh(lb_priv->fp);
182	if (unlikely(!fp))
183		return 0;
184	lhash = SK_RUN_FILTER(fp, skb);
185	c = (char *) &lhash;
186	return c[0] ^ c[1] ^ c[2] ^ c[3];
187}
188
189static void lb_update_tx_stats(unsigned int tx_bytes, struct lb_priv *lb_priv,
190			       struct lb_port_priv *lb_port_priv,
191			       unsigned char hash)
192{
193	struct lb_pcpu_stats *pcpu_stats;
194	struct lb_stats *port_stats;
195	struct lb_stats *hash_stats;
196
197	pcpu_stats = this_cpu_ptr(lb_priv->pcpu_stats);
198	port_stats = this_cpu_ptr(lb_port_priv->pcpu_stats);
199	hash_stats = &pcpu_stats->hash_stats[hash];
200	u64_stats_update_begin(&pcpu_stats->syncp);
201	port_stats->tx_bytes += tx_bytes;
202	hash_stats->tx_bytes += tx_bytes;
203	u64_stats_update_end(&pcpu_stats->syncp);
204}
205
206static bool lb_transmit(struct team *team, struct sk_buff *skb)
207{
208	struct lb_priv *lb_priv = get_lb_priv(team);
209	lb_select_tx_port_func_t *select_tx_port_func;
210	struct team_port *port;
211	unsigned char hash;
212	unsigned int tx_bytes = skb->len;
213
214	hash = lb_get_skb_hash(lb_priv, skb);
215	select_tx_port_func = rcu_dereference_bh(lb_priv->select_tx_port_func);
216	port = select_tx_port_func(team, lb_priv, skb, hash);
217	if (unlikely(!port))
218		goto drop;
219	if (team_dev_queue_xmit(team, port, skb))
220		return false;
221	lb_update_tx_stats(tx_bytes, lb_priv, get_lb_port_priv(port), hash);
222	return true;
223
224drop:
225	dev_kfree_skb_any(skb);
226	return false;
227}
228
229static int lb_bpf_func_get(struct team *team, struct team_gsetter_ctx *ctx)
230{
231	struct lb_priv *lb_priv = get_lb_priv(team);
232
233	if (!lb_priv->ex->orig_fprog) {
234		ctx->data.bin_val.len = 0;
235		ctx->data.bin_val.ptr = NULL;
236		return 0;
237	}
238	ctx->data.bin_val.len = lb_priv->ex->orig_fprog->len *
239				sizeof(struct sock_filter);
240	ctx->data.bin_val.ptr = lb_priv->ex->orig_fprog->filter;
241	return 0;
242}
243
244static int __fprog_create(struct sock_fprog **pfprog, u32 data_len,
245			  const void *data)
246{
247	struct sock_fprog *fprog;
248	struct sock_filter *filter = (struct sock_filter *) data;
249
250	if (data_len % sizeof(struct sock_filter))
251		return -EINVAL;
252	fprog = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
253	if (!fprog)
254		return -ENOMEM;
255	fprog->filter = kmemdup(filter, data_len, GFP_KERNEL);
256	if (!fprog->filter) {
257		kfree(fprog);
258		return -ENOMEM;
259	}
260	fprog->len = data_len / sizeof(struct sock_filter);
261	*pfprog = fprog;
262	return 0;
263}
264
265static void __fprog_destroy(struct sock_fprog *fprog)
266{
267	kfree(fprog->filter);
268	kfree(fprog);
269}
270
271static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
272{
273	struct lb_priv *lb_priv = get_lb_priv(team);
274	struct sk_filter *fp = NULL;
275	struct sk_filter *orig_fp;
276	struct sock_fprog *fprog = NULL;
277	int err;
278
279	if (ctx->data.bin_val.len) {
280		err = __fprog_create(&fprog, ctx->data.bin_val.len,
281				     ctx->data.bin_val.ptr);
282		if (err)
283			return err;
284		err = sk_unattached_filter_create(&fp, fprog);
285		if (err) {
286			__fprog_destroy(fprog);
287			return err;
288		}
289	}
290
291	if (lb_priv->ex->orig_fprog) {
292		/* Clear old filter data */
293		__fprog_destroy(lb_priv->ex->orig_fprog);
294		orig_fp = rcu_dereference_protected(lb_priv->fp,
295						lockdep_is_held(&team->lock));
296		sk_unattached_filter_destroy(orig_fp);
297	}
298
299	rcu_assign_pointer(lb_priv->fp, fp);
300	lb_priv->ex->orig_fprog = fprog;
 
 
 
 
 
301	return 0;
302}
303
304static int lb_tx_method_get(struct team *team, struct team_gsetter_ctx *ctx)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305{
306	struct lb_priv *lb_priv = get_lb_priv(team);
307	lb_select_tx_port_func_t *func;
308	char *name;
309
310	func = rcu_dereference_protected(lb_priv->select_tx_port_func,
311					 lockdep_is_held(&team->lock));
312	name = lb_select_tx_port_get_name(func);
313	BUG_ON(!name);
314	ctx->data.str_val = name;
315	return 0;
316}
317
318static int lb_tx_method_set(struct team *team, struct team_gsetter_ctx *ctx)
319{
320	struct lb_priv *lb_priv = get_lb_priv(team);
321	lb_select_tx_port_func_t *func;
322
323	func = lb_select_tx_port_get_func(ctx->data.str_val);
324	if (!func)
325		return -EINVAL;
326	rcu_assign_pointer(lb_priv->select_tx_port_func, func);
327	return 0;
328}
329
330static int lb_tx_hash_to_port_mapping_init(struct team *team,
331					   struct team_option_inst_info *info)
332{
333	struct lb_priv *lb_priv = get_lb_priv(team);
334	unsigned char hash = info->array_index;
335
336	LB_HTPM_OPT_INST_INFO_BY_HASH(lb_priv, hash) = info;
337	return 0;
338}
339
340static int lb_tx_hash_to_port_mapping_get(struct team *team,
341					  struct team_gsetter_ctx *ctx)
342{
343	struct lb_priv *lb_priv = get_lb_priv(team);
344	struct team_port *port;
345	unsigned char hash = ctx->info->array_index;
346
347	port = LB_HTPM_PORT_BY_HASH(lb_priv, hash);
348	ctx->data.u32_val = port ? port->dev->ifindex : 0;
349	return 0;
350}
351
352static int lb_tx_hash_to_port_mapping_set(struct team *team,
353					  struct team_gsetter_ctx *ctx)
354{
355	struct lb_priv *lb_priv = get_lb_priv(team);
356	struct team_port *port;
357	unsigned char hash = ctx->info->array_index;
358
359	list_for_each_entry(port, &team->port_list, list) {
360		if (ctx->data.u32_val == port->dev->ifindex &&
361		    team_port_enabled(port)) {
362			rcu_assign_pointer(LB_HTPM_PORT_BY_HASH(lb_priv, hash),
363					   port);
364			return 0;
365		}
366	}
367	return -ENODEV;
368}
369
370static int lb_hash_stats_init(struct team *team,
371			      struct team_option_inst_info *info)
372{
373	struct lb_priv *lb_priv = get_lb_priv(team);
374	unsigned char hash = info->array_index;
375
376	lb_priv->ex->stats.info[hash].opt_inst_info = info;
377	return 0;
378}
379
380static int lb_hash_stats_get(struct team *team, struct team_gsetter_ctx *ctx)
381{
382	struct lb_priv *lb_priv = get_lb_priv(team);
383	unsigned char hash = ctx->info->array_index;
384
385	ctx->data.bin_val.ptr = &lb_priv->ex->stats.info[hash].stats;
386	ctx->data.bin_val.len = sizeof(struct lb_stats);
387	return 0;
388}
389
390static int lb_port_stats_init(struct team *team,
391			      struct team_option_inst_info *info)
392{
393	struct team_port *port = info->port;
394	struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
395
396	lb_port_priv->stats_info.opt_inst_info = info;
397	return 0;
398}
399
400static int lb_port_stats_get(struct team *team, struct team_gsetter_ctx *ctx)
401{
402	struct team_port *port = ctx->info->port;
403	struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
404
405	ctx->data.bin_val.ptr = &lb_port_priv->stats_info.stats;
406	ctx->data.bin_val.len = sizeof(struct lb_stats);
407	return 0;
408}
409
410static void __lb_stats_info_refresh_prepare(struct lb_stats_info *s_info)
411{
412	memcpy(&s_info->last_stats, &s_info->stats, sizeof(struct lb_stats));
413	memset(&s_info->stats, 0, sizeof(struct lb_stats));
414}
415
416static bool __lb_stats_info_refresh_check(struct lb_stats_info *s_info,
417					  struct team *team)
418{
419	if (memcmp(&s_info->last_stats, &s_info->stats,
420	    sizeof(struct lb_stats))) {
421		team_option_inst_set_change(s_info->opt_inst_info);
422		return true;
423	}
424	return false;
425}
426
427static void __lb_one_cpu_stats_add(struct lb_stats *acc_stats,
428				   struct lb_stats *cpu_stats,
429				   struct u64_stats_sync *syncp)
430{
431	unsigned int start;
432	struct lb_stats tmp;
433
434	do {
435		start = u64_stats_fetch_begin_irq(syncp);
436		tmp.tx_bytes = cpu_stats->tx_bytes;
437	} while (u64_stats_fetch_retry_irq(syncp, start));
438	acc_stats->tx_bytes += tmp.tx_bytes;
439}
440
441static void lb_stats_refresh(struct work_struct *work)
442{
443	struct team *team;
444	struct lb_priv *lb_priv;
445	struct lb_priv_ex *lb_priv_ex;
446	struct lb_pcpu_stats *pcpu_stats;
447	struct lb_stats *stats;
448	struct lb_stats_info *s_info;
449	struct team_port *port;
450	bool changed = false;
451	int i;
452	int j;
453
454	lb_priv_ex = container_of(work, struct lb_priv_ex,
455				  stats.refresh_dw.work);
456
457	team = lb_priv_ex->team;
458	lb_priv = get_lb_priv(team);
459
460	if (!mutex_trylock(&team->lock)) {
461		schedule_delayed_work(&lb_priv_ex->stats.refresh_dw, 0);
462		return;
463	}
464
465	for (j = 0; j < LB_TX_HASHTABLE_SIZE; j++) {
466		s_info = &lb_priv->ex->stats.info[j];
467		__lb_stats_info_refresh_prepare(s_info);
468		for_each_possible_cpu(i) {
469			pcpu_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
470			stats = &pcpu_stats->hash_stats[j];
471			__lb_one_cpu_stats_add(&s_info->stats, stats,
472					       &pcpu_stats->syncp);
473		}
474		changed |= __lb_stats_info_refresh_check(s_info, team);
475	}
476
477	list_for_each_entry(port, &team->port_list, list) {
478		struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
479
480		s_info = &lb_port_priv->stats_info;
481		__lb_stats_info_refresh_prepare(s_info);
482		for_each_possible_cpu(i) {
483			pcpu_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
484			stats = per_cpu_ptr(lb_port_priv->pcpu_stats, i);
485			__lb_one_cpu_stats_add(&s_info->stats, stats,
486					       &pcpu_stats->syncp);
487		}
488		changed |= __lb_stats_info_refresh_check(s_info, team);
489	}
490
491	if (changed)
492		team_options_change_check(team);
493
494	schedule_delayed_work(&lb_priv_ex->stats.refresh_dw,
495			      (lb_priv_ex->stats.refresh_interval * HZ) / 10);
496
497	mutex_unlock(&team->lock);
498}
499
500static int lb_stats_refresh_interval_get(struct team *team,
501					 struct team_gsetter_ctx *ctx)
502{
503	struct lb_priv *lb_priv = get_lb_priv(team);
504
505	ctx->data.u32_val = lb_priv->ex->stats.refresh_interval;
506	return 0;
507}
508
509static int lb_stats_refresh_interval_set(struct team *team,
510					 struct team_gsetter_ctx *ctx)
511{
512	struct lb_priv *lb_priv = get_lb_priv(team);
513	unsigned int interval;
514
515	interval = ctx->data.u32_val;
516	if (lb_priv->ex->stats.refresh_interval == interval)
517		return 0;
518	lb_priv->ex->stats.refresh_interval = interval;
519	if (interval)
520		schedule_delayed_work(&lb_priv->ex->stats.refresh_dw, 0);
521	else
522		cancel_delayed_work(&lb_priv->ex->stats.refresh_dw);
523	return 0;
524}
525
526static const struct team_option lb_options[] = {
527	{
528		.name = "bpf_hash_func",
529		.type = TEAM_OPTION_TYPE_BINARY,
530		.getter = lb_bpf_func_get,
531		.setter = lb_bpf_func_set,
532	},
533	{
534		.name = "lb_tx_method",
535		.type = TEAM_OPTION_TYPE_STRING,
536		.getter = lb_tx_method_get,
537		.setter = lb_tx_method_set,
538	},
539	{
540		.name = "lb_tx_hash_to_port_mapping",
541		.array_size = LB_TX_HASHTABLE_SIZE,
542		.type = TEAM_OPTION_TYPE_U32,
543		.init = lb_tx_hash_to_port_mapping_init,
544		.getter = lb_tx_hash_to_port_mapping_get,
545		.setter = lb_tx_hash_to_port_mapping_set,
546	},
547	{
548		.name = "lb_hash_stats",
549		.array_size = LB_TX_HASHTABLE_SIZE,
550		.type = TEAM_OPTION_TYPE_BINARY,
551		.init = lb_hash_stats_init,
552		.getter = lb_hash_stats_get,
553	},
554	{
555		.name = "lb_port_stats",
556		.per_port = true,
557		.type = TEAM_OPTION_TYPE_BINARY,
558		.init = lb_port_stats_init,
559		.getter = lb_port_stats_get,
560	},
561	{
562		.name = "lb_stats_refresh_interval",
563		.type = TEAM_OPTION_TYPE_U32,
564		.getter = lb_stats_refresh_interval_get,
565		.setter = lb_stats_refresh_interval_set,
566	},
567};
568
569static int lb_init(struct team *team)
570{
571	struct lb_priv *lb_priv = get_lb_priv(team);
572	lb_select_tx_port_func_t *func;
573	int i, err;
574
575	/* set default tx port selector */
576	func = lb_select_tx_port_get_func("hash");
577	BUG_ON(!func);
578	rcu_assign_pointer(lb_priv->select_tx_port_func, func);
579
580	lb_priv->ex = kzalloc(sizeof(*lb_priv->ex), GFP_KERNEL);
581	if (!lb_priv->ex)
582		return -ENOMEM;
583	lb_priv->ex->team = team;
584
585	lb_priv->pcpu_stats = alloc_percpu(struct lb_pcpu_stats);
586	if (!lb_priv->pcpu_stats) {
587		err = -ENOMEM;
588		goto err_alloc_pcpu_stats;
589	}
590
591	for_each_possible_cpu(i) {
592		struct lb_pcpu_stats *team_lb_stats;
593		team_lb_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
594		u64_stats_init(&team_lb_stats->syncp);
595	}
596
597
598	INIT_DELAYED_WORK(&lb_priv->ex->stats.refresh_dw, lb_stats_refresh);
599
600	err = team_options_register(team, lb_options, ARRAY_SIZE(lb_options));
601	if (err)
602		goto err_options_register;
603	return 0;
604
605err_options_register:
606	free_percpu(lb_priv->pcpu_stats);
607err_alloc_pcpu_stats:
608	kfree(lb_priv->ex);
609	return err;
610}
611
612static void lb_exit(struct team *team)
613{
614	struct lb_priv *lb_priv = get_lb_priv(team);
615
616	team_options_unregister(team, lb_options,
617				ARRAY_SIZE(lb_options));
 
618	cancel_delayed_work_sync(&lb_priv->ex->stats.refresh_dw);
619	free_percpu(lb_priv->pcpu_stats);
620	kfree(lb_priv->ex);
621}
622
623static int lb_port_enter(struct team *team, struct team_port *port)
624{
625	struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
626
627	lb_port_priv->pcpu_stats = alloc_percpu(struct lb_stats);
628	if (!lb_port_priv->pcpu_stats)
629		return -ENOMEM;
630	return 0;
631}
632
633static void lb_port_leave(struct team *team, struct team_port *port)
634{
635	struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
636
637	free_percpu(lb_port_priv->pcpu_stats);
638}
639
640static void lb_port_disabled(struct team *team, struct team_port *port)
641{
642	lb_tx_hash_to_port_mapping_null_port(team, port);
643}
644
645static const struct team_mode_ops lb_mode_ops = {
646	.init			= lb_init,
647	.exit			= lb_exit,
648	.port_enter		= lb_port_enter,
649	.port_leave		= lb_port_leave,
650	.port_disabled		= lb_port_disabled,
 
651	.transmit		= lb_transmit,
652};
653
654static const struct team_mode lb_mode = {
655	.kind		= "loadbalance",
656	.owner		= THIS_MODULE,
657	.priv_size	= sizeof(struct lb_priv),
658	.port_priv_size	= sizeof(struct lb_port_priv),
659	.ops		= &lb_mode_ops,
 
660};
661
662static int __init lb_init_module(void)
663{
664	return team_mode_register(&lb_mode);
665}
666
667static void __exit lb_cleanup_module(void)
668{
669	team_mode_unregister(&lb_mode);
670}
671
672module_init(lb_init_module);
673module_exit(lb_cleanup_module);
674
675MODULE_LICENSE("GPL v2");
676MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
677MODULE_DESCRIPTION("Load-balancing mode for team");
678MODULE_ALIAS("team-mode-loadbalance");
v6.8
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * drivers/net/team/team_mode_loadbalance.c - Load-balancing mode for team
  4 * Copyright (c) 2012 Jiri Pirko <jpirko@redhat.com>
 
 
 
 
 
  5 */
  6
  7#include <linux/kernel.h>
  8#include <linux/types.h>
  9#include <linux/module.h>
 10#include <linux/init.h>
 11#include <linux/errno.h>
 12#include <linux/netdevice.h>
 13#include <linux/etherdevice.h>
 14#include <linux/filter.h>
 15#include <linux/if_team.h>
 16
 17static rx_handler_result_t lb_receive(struct team *team, struct team_port *port,
 18				      struct sk_buff *skb)
 19{
 20	if (unlikely(skb->protocol == htons(ETH_P_SLOW))) {
 21		/* LACPDU packets should go to exact delivery */
 22		const unsigned char *dest = eth_hdr(skb)->h_dest;
 23
 24		if (is_link_local_ether_addr(dest) && dest[5] == 0x02)
 25			return RX_HANDLER_EXACT;
 26	}
 27	return RX_HANDLER_ANOTHER;
 28}
 29
 30struct lb_priv;
 31
 32typedef struct team_port *lb_select_tx_port_func_t(struct team *,
 
 
 33						   unsigned char);
 34
 35#define LB_TX_HASHTABLE_SIZE 256 /* hash is a char */
 36
 37struct lb_stats {
 38	u64 tx_bytes;
 39};
 40
 41struct lb_pcpu_stats {
 42	struct lb_stats hash_stats[LB_TX_HASHTABLE_SIZE];
 43	struct u64_stats_sync syncp;
 44};
 45
 46struct lb_stats_info {
 47	struct lb_stats stats;
 48	struct lb_stats last_stats;
 49	struct team_option_inst_info *opt_inst_info;
 50};
 51
 52struct lb_port_mapping {
 53	struct team_port __rcu *port;
 54	struct team_option_inst_info *opt_inst_info;
 55};
 56
 57struct lb_priv_ex {
 58	struct team *team;
 59	struct lb_port_mapping tx_hash_to_port_mapping[LB_TX_HASHTABLE_SIZE];
 60	struct sock_fprog_kern *orig_fprog;
 61	struct {
 62		unsigned int refresh_interval; /* in tenths of second */
 63		struct delayed_work refresh_dw;
 64		struct lb_stats_info info[LB_TX_HASHTABLE_SIZE];
 65	} stats;
 66};
 67
 68struct lb_priv {
 69	struct bpf_prog __rcu *fp;
 70	lb_select_tx_port_func_t __rcu *select_tx_port_func;
 71	struct lb_pcpu_stats __percpu *pcpu_stats;
 72	struct lb_priv_ex *ex; /* priv extension */
 73};
 74
 75static struct lb_priv *get_lb_priv(struct team *team)
 76{
 77	return (struct lb_priv *) &team->mode_priv;
 78}
 79
 80struct lb_port_priv {
 81	struct lb_stats __percpu *pcpu_stats;
 82	struct lb_stats_info stats_info;
 83};
 84
 85static struct lb_port_priv *get_lb_port_priv(struct team_port *port)
 86{
 87	return (struct lb_port_priv *) &port->mode_priv;
 88}
 89
 90#define LB_HTPM_PORT_BY_HASH(lp_priv, hash) \
 91	(lb_priv)->ex->tx_hash_to_port_mapping[hash].port
 92
 93#define LB_HTPM_OPT_INST_INFO_BY_HASH(lp_priv, hash) \
 94	(lb_priv)->ex->tx_hash_to_port_mapping[hash].opt_inst_info
 95
 96static void lb_tx_hash_to_port_mapping_null_port(struct team *team,
 97						 struct team_port *port)
 98{
 99	struct lb_priv *lb_priv = get_lb_priv(team);
100	bool changed = false;
101	int i;
102
103	for (i = 0; i < LB_TX_HASHTABLE_SIZE; i++) {
104		struct lb_port_mapping *pm;
105
106		pm = &lb_priv->ex->tx_hash_to_port_mapping[i];
107		if (rcu_access_pointer(pm->port) == port) {
108			RCU_INIT_POINTER(pm->port, NULL);
109			team_option_inst_set_change(pm->opt_inst_info);
110			changed = true;
111		}
112	}
113	if (changed)
114		team_options_change_check(team);
115}
116
117/* Basic tx selection based solely by hash */
118static struct team_port *lb_hash_select_tx_port(struct team *team,
 
 
119						unsigned char hash)
120{
121	int port_index = team_num_to_port_index(team, hash);
122
123	return team_get_port_by_index_rcu(team, port_index);
124}
125
126/* Hash to port mapping select tx port */
127static struct team_port *lb_htpm_select_tx_port(struct team *team,
 
 
128						unsigned char hash)
129{
130	struct lb_priv *lb_priv = get_lb_priv(team);
131	struct team_port *port;
132
133	port = rcu_dereference_bh(LB_HTPM_PORT_BY_HASH(lb_priv, hash));
134	if (likely(port))
135		return port;
136	/* If no valid port in the table, fall back to simple hash */
137	return lb_hash_select_tx_port(team, hash);
138}
139
140struct lb_select_tx_port {
141	char *name;
142	lb_select_tx_port_func_t *func;
143};
144
145static const struct lb_select_tx_port lb_select_tx_port_list[] = {
146	{
147		.name = "hash",
148		.func = lb_hash_select_tx_port,
149	},
150	{
151		.name = "hash_to_port_mapping",
152		.func = lb_htpm_select_tx_port,
153	},
154};
155#define LB_SELECT_TX_PORT_LIST_COUNT ARRAY_SIZE(lb_select_tx_port_list)
156
157static char *lb_select_tx_port_get_name(lb_select_tx_port_func_t *func)
158{
159	int i;
160
161	for (i = 0; i < LB_SELECT_TX_PORT_LIST_COUNT; i++) {
162		const struct lb_select_tx_port *item;
163
164		item = &lb_select_tx_port_list[i];
165		if (item->func == func)
166			return item->name;
167	}
168	return NULL;
169}
170
171static lb_select_tx_port_func_t *lb_select_tx_port_get_func(const char *name)
172{
173	int i;
174
175	for (i = 0; i < LB_SELECT_TX_PORT_LIST_COUNT; i++) {
176		const struct lb_select_tx_port *item;
177
178		item = &lb_select_tx_port_list[i];
179		if (!strcmp(item->name, name))
180			return item->func;
181	}
182	return NULL;
183}
184
185static unsigned int lb_get_skb_hash(struct lb_priv *lb_priv,
186				    struct sk_buff *skb)
187{
188	struct bpf_prog *fp;
189	uint32_t lhash;
190	unsigned char *c;
191
192	fp = rcu_dereference_bh(lb_priv->fp);
193	if (unlikely(!fp))
194		return 0;
195	lhash = bpf_prog_run(fp, skb);
196	c = (char *) &lhash;
197	return c[0] ^ c[1] ^ c[2] ^ c[3];
198}
199
200static void lb_update_tx_stats(unsigned int tx_bytes, struct lb_priv *lb_priv,
201			       struct lb_port_priv *lb_port_priv,
202			       unsigned char hash)
203{
204	struct lb_pcpu_stats *pcpu_stats;
205	struct lb_stats *port_stats;
206	struct lb_stats *hash_stats;
207
208	pcpu_stats = this_cpu_ptr(lb_priv->pcpu_stats);
209	port_stats = this_cpu_ptr(lb_port_priv->pcpu_stats);
210	hash_stats = &pcpu_stats->hash_stats[hash];
211	u64_stats_update_begin(&pcpu_stats->syncp);
212	port_stats->tx_bytes += tx_bytes;
213	hash_stats->tx_bytes += tx_bytes;
214	u64_stats_update_end(&pcpu_stats->syncp);
215}
216
217static bool lb_transmit(struct team *team, struct sk_buff *skb)
218{
219	struct lb_priv *lb_priv = get_lb_priv(team);
220	lb_select_tx_port_func_t *select_tx_port_func;
221	struct team_port *port;
222	unsigned char hash;
223	unsigned int tx_bytes = skb->len;
224
225	hash = lb_get_skb_hash(lb_priv, skb);
226	select_tx_port_func = rcu_dereference_bh(lb_priv->select_tx_port_func);
227	port = select_tx_port_func(team, hash);
228	if (unlikely(!port))
229		goto drop;
230	if (team_dev_queue_xmit(team, port, skb))
231		return false;
232	lb_update_tx_stats(tx_bytes, lb_priv, get_lb_port_priv(port), hash);
233	return true;
234
235drop:
236	dev_kfree_skb_any(skb);
237	return false;
238}
239
240static void lb_bpf_func_get(struct team *team, struct team_gsetter_ctx *ctx)
241{
242	struct lb_priv *lb_priv = get_lb_priv(team);
243
244	if (!lb_priv->ex->orig_fprog) {
245		ctx->data.bin_val.len = 0;
246		ctx->data.bin_val.ptr = NULL;
247		return;
248	}
249	ctx->data.bin_val.len = lb_priv->ex->orig_fprog->len *
250				sizeof(struct sock_filter);
251	ctx->data.bin_val.ptr = lb_priv->ex->orig_fprog->filter;
 
252}
253
254static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
255			  const void *data)
256{
257	struct sock_fprog_kern *fprog;
258	struct sock_filter *filter = (struct sock_filter *) data;
259
260	if (data_len % sizeof(struct sock_filter))
261		return -EINVAL;
262	fprog = kmalloc(sizeof(*fprog), GFP_KERNEL);
263	if (!fprog)
264		return -ENOMEM;
265	fprog->filter = kmemdup(filter, data_len, GFP_KERNEL);
266	if (!fprog->filter) {
267		kfree(fprog);
268		return -ENOMEM;
269	}
270	fprog->len = data_len / sizeof(struct sock_filter);
271	*pfprog = fprog;
272	return 0;
273}
274
275static void __fprog_destroy(struct sock_fprog_kern *fprog)
276{
277	kfree(fprog->filter);
278	kfree(fprog);
279}
280
281static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
282{
283	struct lb_priv *lb_priv = get_lb_priv(team);
284	struct bpf_prog *fp = NULL;
285	struct bpf_prog *orig_fp = NULL;
286	struct sock_fprog_kern *fprog = NULL;
287	int err;
288
289	if (ctx->data.bin_val.len) {
290		err = __fprog_create(&fprog, ctx->data.bin_val.len,
291				     ctx->data.bin_val.ptr);
292		if (err)
293			return err;
294		err = bpf_prog_create(&fp, fprog);
295		if (err) {
296			__fprog_destroy(fprog);
297			return err;
298		}
299	}
300
301	if (lb_priv->ex->orig_fprog) {
302		/* Clear old filter data */
303		__fprog_destroy(lb_priv->ex->orig_fprog);
304		orig_fp = rcu_dereference_protected(lb_priv->fp,
305						lockdep_is_held(&team->lock));
 
306	}
307
308	rcu_assign_pointer(lb_priv->fp, fp);
309	lb_priv->ex->orig_fprog = fprog;
310
311	if (orig_fp) {
312		synchronize_rcu();
313		bpf_prog_destroy(orig_fp);
314	}
315	return 0;
316}
317
318static void lb_bpf_func_free(struct team *team)
319{
320	struct lb_priv *lb_priv = get_lb_priv(team);
321	struct bpf_prog *fp;
322
323	if (!lb_priv->ex->orig_fprog)
324		return;
325
326	__fprog_destroy(lb_priv->ex->orig_fprog);
327	fp = rcu_dereference_protected(lb_priv->fp,
328				       lockdep_is_held(&team->lock));
329	bpf_prog_destroy(fp);
330}
331
332static void lb_tx_method_get(struct team *team, struct team_gsetter_ctx *ctx)
333{
334	struct lb_priv *lb_priv = get_lb_priv(team);
335	lb_select_tx_port_func_t *func;
336	char *name;
337
338	func = rcu_dereference_protected(lb_priv->select_tx_port_func,
339					 lockdep_is_held(&team->lock));
340	name = lb_select_tx_port_get_name(func);
341	BUG_ON(!name);
342	ctx->data.str_val = name;
 
343}
344
345static int lb_tx_method_set(struct team *team, struct team_gsetter_ctx *ctx)
346{
347	struct lb_priv *lb_priv = get_lb_priv(team);
348	lb_select_tx_port_func_t *func;
349
350	func = lb_select_tx_port_get_func(ctx->data.str_val);
351	if (!func)
352		return -EINVAL;
353	rcu_assign_pointer(lb_priv->select_tx_port_func, func);
354	return 0;
355}
356
357static void lb_tx_hash_to_port_mapping_init(struct team *team,
358					    struct team_option_inst_info *info)
359{
360	struct lb_priv *lb_priv = get_lb_priv(team);
361	unsigned char hash = info->array_index;
362
363	LB_HTPM_OPT_INST_INFO_BY_HASH(lb_priv, hash) = info;
 
364}
365
366static void lb_tx_hash_to_port_mapping_get(struct team *team,
367					   struct team_gsetter_ctx *ctx)
368{
369	struct lb_priv *lb_priv = get_lb_priv(team);
370	struct team_port *port;
371	unsigned char hash = ctx->info->array_index;
372
373	port = LB_HTPM_PORT_BY_HASH(lb_priv, hash);
374	ctx->data.u32_val = port ? port->dev->ifindex : 0;
 
375}
376
377static int lb_tx_hash_to_port_mapping_set(struct team *team,
378					  struct team_gsetter_ctx *ctx)
379{
380	struct lb_priv *lb_priv = get_lb_priv(team);
381	struct team_port *port;
382	unsigned char hash = ctx->info->array_index;
383
384	list_for_each_entry(port, &team->port_list, list) {
385		if (ctx->data.u32_val == port->dev->ifindex &&
386		    team_port_enabled(port)) {
387			rcu_assign_pointer(LB_HTPM_PORT_BY_HASH(lb_priv, hash),
388					   port);
389			return 0;
390		}
391	}
392	return -ENODEV;
393}
394
395static void lb_hash_stats_init(struct team *team,
396			       struct team_option_inst_info *info)
397{
398	struct lb_priv *lb_priv = get_lb_priv(team);
399	unsigned char hash = info->array_index;
400
401	lb_priv->ex->stats.info[hash].opt_inst_info = info;
 
402}
403
404static void lb_hash_stats_get(struct team *team, struct team_gsetter_ctx *ctx)
405{
406	struct lb_priv *lb_priv = get_lb_priv(team);
407	unsigned char hash = ctx->info->array_index;
408
409	ctx->data.bin_val.ptr = &lb_priv->ex->stats.info[hash].stats;
410	ctx->data.bin_val.len = sizeof(struct lb_stats);
 
411}
412
413static void lb_port_stats_init(struct team *team,
414			       struct team_option_inst_info *info)
415{
416	struct team_port *port = info->port;
417	struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
418
419	lb_port_priv->stats_info.opt_inst_info = info;
 
420}
421
422static void lb_port_stats_get(struct team *team, struct team_gsetter_ctx *ctx)
423{
424	struct team_port *port = ctx->info->port;
425	struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
426
427	ctx->data.bin_val.ptr = &lb_port_priv->stats_info.stats;
428	ctx->data.bin_val.len = sizeof(struct lb_stats);
 
429}
430
431static void __lb_stats_info_refresh_prepare(struct lb_stats_info *s_info)
432{
433	memcpy(&s_info->last_stats, &s_info->stats, sizeof(struct lb_stats));
434	memset(&s_info->stats, 0, sizeof(struct lb_stats));
435}
436
437static bool __lb_stats_info_refresh_check(struct lb_stats_info *s_info,
438					  struct team *team)
439{
440	if (memcmp(&s_info->last_stats, &s_info->stats,
441	    sizeof(struct lb_stats))) {
442		team_option_inst_set_change(s_info->opt_inst_info);
443		return true;
444	}
445	return false;
446}
447
448static void __lb_one_cpu_stats_add(struct lb_stats *acc_stats,
449				   struct lb_stats *cpu_stats,
450				   struct u64_stats_sync *syncp)
451{
452	unsigned int start;
453	struct lb_stats tmp;
454
455	do {
456		start = u64_stats_fetch_begin(syncp);
457		tmp.tx_bytes = cpu_stats->tx_bytes;
458	} while (u64_stats_fetch_retry(syncp, start));
459	acc_stats->tx_bytes += tmp.tx_bytes;
460}
461
462static void lb_stats_refresh(struct work_struct *work)
463{
464	struct team *team;
465	struct lb_priv *lb_priv;
466	struct lb_priv_ex *lb_priv_ex;
467	struct lb_pcpu_stats *pcpu_stats;
468	struct lb_stats *stats;
469	struct lb_stats_info *s_info;
470	struct team_port *port;
471	bool changed = false;
472	int i;
473	int j;
474
475	lb_priv_ex = container_of(work, struct lb_priv_ex,
476				  stats.refresh_dw.work);
477
478	team = lb_priv_ex->team;
479	lb_priv = get_lb_priv(team);
480
481	if (!mutex_trylock(&team->lock)) {
482		schedule_delayed_work(&lb_priv_ex->stats.refresh_dw, 0);
483		return;
484	}
485
486	for (j = 0; j < LB_TX_HASHTABLE_SIZE; j++) {
487		s_info = &lb_priv->ex->stats.info[j];
488		__lb_stats_info_refresh_prepare(s_info);
489		for_each_possible_cpu(i) {
490			pcpu_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
491			stats = &pcpu_stats->hash_stats[j];
492			__lb_one_cpu_stats_add(&s_info->stats, stats,
493					       &pcpu_stats->syncp);
494		}
495		changed |= __lb_stats_info_refresh_check(s_info, team);
496	}
497
498	list_for_each_entry(port, &team->port_list, list) {
499		struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
500
501		s_info = &lb_port_priv->stats_info;
502		__lb_stats_info_refresh_prepare(s_info);
503		for_each_possible_cpu(i) {
504			pcpu_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
505			stats = per_cpu_ptr(lb_port_priv->pcpu_stats, i);
506			__lb_one_cpu_stats_add(&s_info->stats, stats,
507					       &pcpu_stats->syncp);
508		}
509		changed |= __lb_stats_info_refresh_check(s_info, team);
510	}
511
512	if (changed)
513		team_options_change_check(team);
514
515	schedule_delayed_work(&lb_priv_ex->stats.refresh_dw,
516			      (lb_priv_ex->stats.refresh_interval * HZ) / 10);
517
518	mutex_unlock(&team->lock);
519}
520
521static void lb_stats_refresh_interval_get(struct team *team,
522					  struct team_gsetter_ctx *ctx)
523{
524	struct lb_priv *lb_priv = get_lb_priv(team);
525
526	ctx->data.u32_val = lb_priv->ex->stats.refresh_interval;
 
527}
528
529static int lb_stats_refresh_interval_set(struct team *team,
530					 struct team_gsetter_ctx *ctx)
531{
532	struct lb_priv *lb_priv = get_lb_priv(team);
533	unsigned int interval;
534
535	interval = ctx->data.u32_val;
536	if (lb_priv->ex->stats.refresh_interval == interval)
537		return 0;
538	lb_priv->ex->stats.refresh_interval = interval;
539	if (interval)
540		schedule_delayed_work(&lb_priv->ex->stats.refresh_dw, 0);
541	else
542		cancel_delayed_work(&lb_priv->ex->stats.refresh_dw);
543	return 0;
544}
545
546static const struct team_option lb_options[] = {
547	{
548		.name = "bpf_hash_func",
549		.type = TEAM_OPTION_TYPE_BINARY,
550		.getter = lb_bpf_func_get,
551		.setter = lb_bpf_func_set,
552	},
553	{
554		.name = "lb_tx_method",
555		.type = TEAM_OPTION_TYPE_STRING,
556		.getter = lb_tx_method_get,
557		.setter = lb_tx_method_set,
558	},
559	{
560		.name = "lb_tx_hash_to_port_mapping",
561		.array_size = LB_TX_HASHTABLE_SIZE,
562		.type = TEAM_OPTION_TYPE_U32,
563		.init = lb_tx_hash_to_port_mapping_init,
564		.getter = lb_tx_hash_to_port_mapping_get,
565		.setter = lb_tx_hash_to_port_mapping_set,
566	},
567	{
568		.name = "lb_hash_stats",
569		.array_size = LB_TX_HASHTABLE_SIZE,
570		.type = TEAM_OPTION_TYPE_BINARY,
571		.init = lb_hash_stats_init,
572		.getter = lb_hash_stats_get,
573	},
574	{
575		.name = "lb_port_stats",
576		.per_port = true,
577		.type = TEAM_OPTION_TYPE_BINARY,
578		.init = lb_port_stats_init,
579		.getter = lb_port_stats_get,
580	},
581	{
582		.name = "lb_stats_refresh_interval",
583		.type = TEAM_OPTION_TYPE_U32,
584		.getter = lb_stats_refresh_interval_get,
585		.setter = lb_stats_refresh_interval_set,
586	},
587};
588
589static int lb_init(struct team *team)
590{
591	struct lb_priv *lb_priv = get_lb_priv(team);
592	lb_select_tx_port_func_t *func;
593	int i, err;
594
595	/* set default tx port selector */
596	func = lb_select_tx_port_get_func("hash");
597	BUG_ON(!func);
598	rcu_assign_pointer(lb_priv->select_tx_port_func, func);
599
600	lb_priv->ex = kzalloc(sizeof(*lb_priv->ex), GFP_KERNEL);
601	if (!lb_priv->ex)
602		return -ENOMEM;
603	lb_priv->ex->team = team;
604
605	lb_priv->pcpu_stats = alloc_percpu(struct lb_pcpu_stats);
606	if (!lb_priv->pcpu_stats) {
607		err = -ENOMEM;
608		goto err_alloc_pcpu_stats;
609	}
610
611	for_each_possible_cpu(i) {
612		struct lb_pcpu_stats *team_lb_stats;
613		team_lb_stats = per_cpu_ptr(lb_priv->pcpu_stats, i);
614		u64_stats_init(&team_lb_stats->syncp);
615	}
616
617
618	INIT_DELAYED_WORK(&lb_priv->ex->stats.refresh_dw, lb_stats_refresh);
619
620	err = team_options_register(team, lb_options, ARRAY_SIZE(lb_options));
621	if (err)
622		goto err_options_register;
623	return 0;
624
625err_options_register:
626	free_percpu(lb_priv->pcpu_stats);
627err_alloc_pcpu_stats:
628	kfree(lb_priv->ex);
629	return err;
630}
631
632static void lb_exit(struct team *team)
633{
634	struct lb_priv *lb_priv = get_lb_priv(team);
635
636	team_options_unregister(team, lb_options,
637				ARRAY_SIZE(lb_options));
638	lb_bpf_func_free(team);
639	cancel_delayed_work_sync(&lb_priv->ex->stats.refresh_dw);
640	free_percpu(lb_priv->pcpu_stats);
641	kfree(lb_priv->ex);
642}
643
644static int lb_port_enter(struct team *team, struct team_port *port)
645{
646	struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
647
648	lb_port_priv->pcpu_stats = alloc_percpu(struct lb_stats);
649	if (!lb_port_priv->pcpu_stats)
650		return -ENOMEM;
651	return 0;
652}
653
654static void lb_port_leave(struct team *team, struct team_port *port)
655{
656	struct lb_port_priv *lb_port_priv = get_lb_port_priv(port);
657
658	free_percpu(lb_port_priv->pcpu_stats);
659}
660
661static void lb_port_disabled(struct team *team, struct team_port *port)
662{
663	lb_tx_hash_to_port_mapping_null_port(team, port);
664}
665
666static const struct team_mode_ops lb_mode_ops = {
667	.init			= lb_init,
668	.exit			= lb_exit,
669	.port_enter		= lb_port_enter,
670	.port_leave		= lb_port_leave,
671	.port_disabled		= lb_port_disabled,
672	.receive		= lb_receive,
673	.transmit		= lb_transmit,
674};
675
676static const struct team_mode lb_mode = {
677	.kind		= "loadbalance",
678	.owner		= THIS_MODULE,
679	.priv_size	= sizeof(struct lb_priv),
680	.port_priv_size	= sizeof(struct lb_port_priv),
681	.ops		= &lb_mode_ops,
682	.lag_tx_type	= NETDEV_LAG_TX_TYPE_HASH,
683};
684
685static int __init lb_init_module(void)
686{
687	return team_mode_register(&lb_mode);
688}
689
690static void __exit lb_cleanup_module(void)
691{
692	team_mode_unregister(&lb_mode);
693}
694
695module_init(lb_init_module);
696module_exit(lb_cleanup_module);
697
698MODULE_LICENSE("GPL v2");
699MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
700MODULE_DESCRIPTION("Load-balancing mode for team");
701MODULE_ALIAS_TEAM_MODE("loadbalance");