Skip to content

Commit

Permalink
s390/qeth: add wrapper for IP table access
Browse files Browse the repository at this point in the history
Extract a little helper, so that high-level callers can manipulate the
IP table without worrying about the locking. This will make it easier
to convert the code to a different locking primitive later on.

Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Julian Wiedmann authored and David S. Miller committed Mar 28, 2019
1 parent 5c0aebc commit 05a1785
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions drivers/s390/net/qeth_l3_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
return rc;
}

static int qeth_l3_modify_ip(struct qeth_card *card, struct qeth_ipaddr *addr,
bool add)
{
int rc;

spin_lock_bh(&card->ip_lock);
rc = add ? qeth_l3_add_ip(card, addr) : qeth_l3_delete_ip(card, addr);
spin_unlock_bh(&card->ip_lock);

return rc;
}

static void qeth_l3_drain_rx_mode_cache(struct qeth_card *card)
{
struct qeth_ipaddr *addr;
Expand Down Expand Up @@ -636,35 +648,28 @@ int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
enum qeth_prot_versions proto)
{
struct qeth_ipaddr addr;
int rc;

qeth_l3_init_ipaddr(&addr, type, proto);
if (proto == QETH_PROT_IPV4)
memcpy(&addr.u.a4.addr, ip, 4);
else
memcpy(&addr.u.a6.addr, ip, 16);

spin_lock_bh(&card->ip_lock);
rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr);
spin_unlock_bh(&card->ip_lock);
return rc;
return qeth_l3_modify_ip(card, &addr, add);
}

int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)
{
struct qeth_ipaddr addr;
int rc, i;
unsigned int i;

qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
addr.u.a6.addr.s6_addr[0] = 0xfe;
addr.u.a6.addr.s6_addr[1] = 0x80;
for (i = 0; i < 8; i++)
addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i];

spin_lock_bh(&card->ip_lock);
rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr);
spin_unlock_bh(&card->ip_lock);
return rc;
return qeth_l3_modify_ip(card, &addr, add);
}

static int qeth_l3_register_addr_entry(struct qeth_card *card,
Expand Down Expand Up @@ -2527,14 +2532,10 @@ static int qeth_l3_handle_ip_event(struct qeth_card *card,
{
switch (event) {
case NETDEV_UP:
spin_lock_bh(&card->ip_lock);
qeth_l3_add_ip(card, addr);
spin_unlock_bh(&card->ip_lock);
qeth_l3_modify_ip(card, addr, true);
return NOTIFY_OK;
case NETDEV_DOWN:
spin_lock_bh(&card->ip_lock);
qeth_l3_delete_ip(card, addr);
spin_unlock_bh(&card->ip_lock);
qeth_l3_modify_ip(card, addr, false);
return NOTIFY_OK;
default:
return NOTIFY_DONE;
Expand Down

0 comments on commit 05a1785

Please sign in to comment.