bonding: move mode setting into separate function
[deliverable/linux.git] / drivers / net / bonding / bond_options.c
CommitLineData
72be35fe
JP
1/*
2 * drivers/net/bond/bond_options.c - bonding options
3 * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
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#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
13#include <linux/errno.h>
14#include <linux/if.h>
15#include "bonding.h"
16
17static bool bond_mode_is_valid(int mode)
18{
19 int i;
20
21 for (i = 0; bond_mode_tbl[i].modename; i++);
22
23 return mode >= 0 && mode < i;
24}
25
26int bond_option_mode_set(struct bonding *bond, int mode)
27{
28 if (!bond_mode_is_valid(mode)) {
29 pr_err("invalid mode value %d.\n", mode);
30 return -EINVAL;
31 }
32
33 if (bond->dev->flags & IFF_UP) {
34 pr_err("%s: unable to update mode because interface is up.\n",
35 bond->dev->name);
36 return -EPERM;
37 }
38
39 if (bond_has_slaves(bond)) {
40 pr_err("%s: unable to update mode because bond has slaves.\n",
41 bond->dev->name);
42 return -EPERM;
43 }
44
45 if (BOND_MODE_IS_LB(mode) && bond->params.arp_interval) {
46 pr_err("%s: %s mode is incompatible with arp monitoring.\n",
47 bond->dev->name, bond_mode_tbl[mode].modename);
48 return -EINVAL;
49 }
50
51 /* don't cache arp_validate between modes */
52 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
53 bond->params.mode = mode;
54 return 0;
55}
This page took 0.036286 seconds and 5 git commands to generate.