diff options
author | Eddie Wai <eddie.wai@broadcom.com> | 2011-06-08 15:29:34 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-06-09 02:52:36 -0400 |
commit | 11f23aa8ccd56786f0a6f04211cf59b3fab2ce08 (patch) | |
tree | 8cee079fc8d62f4a13a04336bc756a981cfceda6 | |
parent | 101c40c8cb0d10c30f423805f9f5b7a75956832d (diff) |
cnic: Randomize initial TCP port for iSCSI connections
This reduces the likelihood of port re-use when re-loading the driver.
Signed-off-by: Eddie Wai <eddie.wai@broadcom.com>
Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/cnic.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/drivers/net/cnic.c b/drivers/net/cnic.c index ea7245c5fb69..a529bde03c56 100644 --- a/drivers/net/cnic.c +++ b/drivers/net/cnic.c | |||
@@ -605,11 +605,12 @@ static int cnic_unregister_device(struct cnic_dev *dev, int ulp_type) | |||
605 | } | 605 | } |
606 | EXPORT_SYMBOL(cnic_unregister_driver); | 606 | EXPORT_SYMBOL(cnic_unregister_driver); |
607 | 607 | ||
608 | static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id) | 608 | static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id, |
609 | u32 next) | ||
609 | { | 610 | { |
610 | id_tbl->start = start_id; | 611 | id_tbl->start = start_id; |
611 | id_tbl->max = size; | 612 | id_tbl->max = size; |
612 | id_tbl->next = 0; | 613 | id_tbl->next = next; |
613 | spin_lock_init(&id_tbl->lock); | 614 | spin_lock_init(&id_tbl->lock); |
614 | id_tbl->table = kzalloc(DIV_ROUND_UP(size, 32) * 4, GFP_KERNEL); | 615 | id_tbl->table = kzalloc(DIV_ROUND_UP(size, 32) * 4, GFP_KERNEL); |
615 | if (!id_tbl->table) | 616 | if (!id_tbl->table) |
@@ -3804,14 +3805,17 @@ static void cnic_cm_free_mem(struct cnic_dev *dev) | |||
3804 | static int cnic_cm_alloc_mem(struct cnic_dev *dev) | 3805 | static int cnic_cm_alloc_mem(struct cnic_dev *dev) |
3805 | { | 3806 | { |
3806 | struct cnic_local *cp = dev->cnic_priv; | 3807 | struct cnic_local *cp = dev->cnic_priv; |
3808 | u32 port_id; | ||
3807 | 3809 | ||
3808 | cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ, | 3810 | cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ, |
3809 | GFP_KERNEL); | 3811 | GFP_KERNEL); |
3810 | if (!cp->csk_tbl) | 3812 | if (!cp->csk_tbl) |
3811 | return -ENOMEM; | 3813 | return -ENOMEM; |
3812 | 3814 | ||
3815 | get_random_bytes(&port_id, sizeof(port_id)); | ||
3816 | port_id %= CNIC_LOCAL_PORT_RANGE; | ||
3813 | if (cnic_init_id_tbl(&cp->csk_port_tbl, CNIC_LOCAL_PORT_RANGE, | 3817 | if (cnic_init_id_tbl(&cp->csk_port_tbl, CNIC_LOCAL_PORT_RANGE, |
3814 | CNIC_LOCAL_PORT_MIN)) { | 3818 | CNIC_LOCAL_PORT_MIN, port_id)) { |
3815 | cnic_cm_free_mem(dev); | 3819 | cnic_cm_free_mem(dev); |
3816 | return -ENOMEM; | 3820 | return -ENOMEM; |
3817 | } | 3821 | } |
@@ -4829,7 +4833,7 @@ static int cnic_start_bnx2x_hw(struct cnic_dev *dev) | |||
4829 | pfid = cp->pfid; | 4833 | pfid = cp->pfid; |
4830 | 4834 | ||
4831 | ret = cnic_init_id_tbl(&cp->cid_tbl, MAX_ISCSI_TBL_SZ, | 4835 | ret = cnic_init_id_tbl(&cp->cid_tbl, MAX_ISCSI_TBL_SZ, |
4832 | cp->iscsi_start_cid); | 4836 | cp->iscsi_start_cid, 0); |
4833 | 4837 | ||
4834 | if (ret) | 4838 | if (ret) |
4835 | return -ENOMEM; | 4839 | return -ENOMEM; |
@@ -4837,7 +4841,7 @@ static int cnic_start_bnx2x_hw(struct cnic_dev *dev) | |||
4837 | if (BNX2X_CHIP_IS_E2(cp->chip_id)) { | 4841 | if (BNX2X_CHIP_IS_E2(cp->chip_id)) { |
4838 | ret = cnic_init_id_tbl(&cp->fcoe_cid_tbl, | 4842 | ret = cnic_init_id_tbl(&cp->fcoe_cid_tbl, |
4839 | BNX2X_FCOE_NUM_CONNECTIONS, | 4843 | BNX2X_FCOE_NUM_CONNECTIONS, |
4840 | cp->fcoe_start_cid); | 4844 | cp->fcoe_start_cid, 0); |
4841 | 4845 | ||
4842 | if (ret) | 4846 | if (ret) |
4843 | return -ENOMEM; | 4847 | return -ENOMEM; |