Skip to content

Commit d9356ed

Browse files
committed
Merge branch 's390-fixes'
Julian Wiedmann says: ==================== s390/qeth: fixes 2017-12-13 some more patches for 4.15, that fix multiple issues with IP Takeover configuration in qeth. Please queue them up for stable kernels as well (4.9 and newer). ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 0f546ff + 02f510f commit d9356ed

File tree

5 files changed

+79
-46
lines changed

5 files changed

+79
-46
lines changed

drivers/s390/net/qeth_core.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,9 @@ enum qeth_cq {
565565
};
566566

567567
struct qeth_ipato {
568-
int enabled;
569-
int invert4;
570-
int invert6;
568+
bool enabled;
569+
bool invert4;
570+
bool invert6;
571571
struct list_head entries;
572572
};
573573

drivers/s390/net/qeth_core_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,9 +1480,9 @@ static int qeth_setup_card(struct qeth_card *card)
14801480
qeth_set_intial_options(card);
14811481
/* IP address takeover */
14821482
INIT_LIST_HEAD(&card->ipato.entries);
1483-
card->ipato.enabled = 0;
1484-
card->ipato.invert4 = 0;
1485-
card->ipato.invert6 = 0;
1483+
card->ipato.enabled = false;
1484+
card->ipato.invert4 = false;
1485+
card->ipato.invert6 = false;
14861486
/* init QDIO stuff */
14871487
qeth_init_qdio_info(card);
14881488
INIT_DELAYED_WORK(&card->buffer_reclaim_work, qeth_buffer_reclaim_work);

drivers/s390/net/qeth_l3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void qeth_l3_del_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
8282
int qeth_l3_add_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
8383
void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions,
8484
const u8 *);
85-
int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
85+
void qeth_l3_update_ipato(struct qeth_card *card);
8686
struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions);
8787
int qeth_l3_add_ip(struct qeth_card *, struct qeth_ipaddr *);
8888
int qeth_l3_delete_ip(struct qeth_card *, struct qeth_ipaddr *);

drivers/s390/net/qeth_l3_main.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
164164
}
165165
}
166166

167-
int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
168-
struct qeth_ipaddr *addr)
167+
static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
168+
struct qeth_ipaddr *addr)
169169
{
170170
struct qeth_ipato_entry *ipatoe;
171171
u8 addr_bits[128] = {0, };
@@ -174,6 +174,8 @@ int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
174174

175175
if (!card->ipato.enabled)
176176
return 0;
177+
if (addr->type != QETH_IP_TYPE_NORMAL)
178+
return 0;
177179

178180
qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
179181
(addr->proto == QETH_PROT_IPV4)? 4:16);
@@ -290,8 +292,7 @@ int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
290292
memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr));
291293
addr->ref_counter = 1;
292294

293-
if (addr->type == QETH_IP_TYPE_NORMAL &&
294-
qeth_l3_is_addr_covered_by_ipato(card, addr)) {
295+
if (qeth_l3_is_addr_covered_by_ipato(card, addr)) {
295296
QETH_CARD_TEXT(card, 2, "tkovaddr");
296297
addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
297298
}
@@ -605,6 +606,27 @@ int qeth_l3_setrouting_v6(struct qeth_card *card)
605606
/*
606607
* IP address takeover related functions
607608
*/
609+
610+
/**
611+
* qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
612+
*
613+
* Caller must hold ip_lock.
614+
*/
615+
void qeth_l3_update_ipato(struct qeth_card *card)
616+
{
617+
struct qeth_ipaddr *addr;
618+
unsigned int i;
619+
620+
hash_for_each(card->ip_htable, i, addr, hnode) {
621+
if (addr->type != QETH_IP_TYPE_NORMAL)
622+
continue;
623+
if (qeth_l3_is_addr_covered_by_ipato(card, addr))
624+
addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
625+
else
626+
addr->set_flags &= ~QETH_IPA_SETIP_TAKEOVER_FLAG;
627+
}
628+
}
629+
608630
static void qeth_l3_clear_ipato_list(struct qeth_card *card)
609631
{
610632
struct qeth_ipato_entry *ipatoe, *tmp;
@@ -616,6 +638,7 @@ static void qeth_l3_clear_ipato_list(struct qeth_card *card)
616638
kfree(ipatoe);
617639
}
618640

641+
qeth_l3_update_ipato(card);
619642
spin_unlock_bh(&card->ip_lock);
620643
}
621644

@@ -640,8 +663,10 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card,
640663
}
641664
}
642665

643-
if (!rc)
666+
if (!rc) {
644667
list_add_tail(&new->entry, &card->ipato.entries);
668+
qeth_l3_update_ipato(card);
669+
}
645670

646671
spin_unlock_bh(&card->ip_lock);
647672

@@ -664,6 +689,7 @@ void qeth_l3_del_ipato_entry(struct qeth_card *card,
664689
(proto == QETH_PROT_IPV4)? 4:16) &&
665690
(ipatoe->mask_bits == mask_bits)) {
666691
list_del(&ipatoe->entry);
692+
qeth_l3_update_ipato(card);
667693
kfree(ipatoe);
668694
}
669695
}

drivers/s390/net/qeth_l3_sys.c

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
370370
struct device_attribute *attr, const char *buf, size_t count)
371371
{
372372
struct qeth_card *card = dev_get_drvdata(dev);
373-
struct qeth_ipaddr *addr;
374-
int i, rc = 0;
373+
bool enable;
374+
int rc = 0;
375375

376376
if (!card)
377377
return -EINVAL;
@@ -384,25 +384,18 @@ static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
384384
}
385385

386386
if (sysfs_streq(buf, "toggle")) {
387-
card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
388-
} else if (sysfs_streq(buf, "1")) {
389-
card->ipato.enabled = 1;
390-
hash_for_each(card->ip_htable, i, addr, hnode) {
391-
if ((addr->type == QETH_IP_TYPE_NORMAL) &&
392-
qeth_l3_is_addr_covered_by_ipato(card, addr))
393-
addr->set_flags |=
394-
QETH_IPA_SETIP_TAKEOVER_FLAG;
395-
}
396-
} else if (sysfs_streq(buf, "0")) {
397-
card->ipato.enabled = 0;
398-
hash_for_each(card->ip_htable, i, addr, hnode) {
399-
if (addr->set_flags &
400-
QETH_IPA_SETIP_TAKEOVER_FLAG)
401-
addr->set_flags &=
402-
~QETH_IPA_SETIP_TAKEOVER_FLAG;
403-
}
404-
} else
387+
enable = !card->ipato.enabled;
388+
} else if (kstrtobool(buf, &enable)) {
405389
rc = -EINVAL;
390+
goto out;
391+
}
392+
393+
if (card->ipato.enabled != enable) {
394+
card->ipato.enabled = enable;
395+
spin_lock_bh(&card->ip_lock);
396+
qeth_l3_update_ipato(card);
397+
spin_unlock_bh(&card->ip_lock);
398+
}
406399
out:
407400
mutex_unlock(&card->conf_mutex);
408401
return rc ? rc : count;
@@ -428,20 +421,27 @@ static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
428421
const char *buf, size_t count)
429422
{
430423
struct qeth_card *card = dev_get_drvdata(dev);
424+
bool invert;
431425
int rc = 0;
432426

433427
if (!card)
434428
return -EINVAL;
435429

436430
mutex_lock(&card->conf_mutex);
437-
if (sysfs_streq(buf, "toggle"))
438-
card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
439-
else if (sysfs_streq(buf, "1"))
440-
card->ipato.invert4 = 1;
441-
else if (sysfs_streq(buf, "0"))
442-
card->ipato.invert4 = 0;
443-
else
431+
if (sysfs_streq(buf, "toggle")) {
432+
invert = !card->ipato.invert4;
433+
} else if (kstrtobool(buf, &invert)) {
444434
rc = -EINVAL;
435+
goto out;
436+
}
437+
438+
if (card->ipato.invert4 != invert) {
439+
card->ipato.invert4 = invert;
440+
spin_lock_bh(&card->ip_lock);
441+
qeth_l3_update_ipato(card);
442+
spin_unlock_bh(&card->ip_lock);
443+
}
444+
out:
445445
mutex_unlock(&card->conf_mutex);
446446
return rc ? rc : count;
447447
}
@@ -607,20 +607,27 @@ static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
607607
struct device_attribute *attr, const char *buf, size_t count)
608608
{
609609
struct qeth_card *card = dev_get_drvdata(dev);
610+
bool invert;
610611
int rc = 0;
611612

612613
if (!card)
613614
return -EINVAL;
614615

615616
mutex_lock(&card->conf_mutex);
616-
if (sysfs_streq(buf, "toggle"))
617-
card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
618-
else if (sysfs_streq(buf, "1"))
619-
card->ipato.invert6 = 1;
620-
else if (sysfs_streq(buf, "0"))
621-
card->ipato.invert6 = 0;
622-
else
617+
if (sysfs_streq(buf, "toggle")) {
618+
invert = !card->ipato.invert6;
619+
} else if (kstrtobool(buf, &invert)) {
623620
rc = -EINVAL;
621+
goto out;
622+
}
623+
624+
if (card->ipato.invert6 != invert) {
625+
card->ipato.invert6 = invert;
626+
spin_lock_bh(&card->ip_lock);
627+
qeth_l3_update_ipato(card);
628+
spin_unlock_bh(&card->ip_lock);
629+
}
630+
out:
624631
mutex_unlock(&card->conf_mutex);
625632
return rc ? rc : count;
626633
}

0 commit comments

Comments
 (0)